pytest is a mature full-featured Python testing tool that helps you write better programs.
I use pytest on every project because of the ease of use and ability to customize/hook into certain aspects of the testing processes. For example, if I want to hook in before each test and process some images (for some reason)... I can do that!
Another great thing about pytest is how easy it is to install plugins. You pip install
the
plugin--that's it! No configuration required.
With xdist
you can run your tests in parallel by providing the -n
flag.
py.test -n 4
will run 4 tests at a time.
$ py.test -n 4
============================ test session starts ============================
platform darwin -- Python 3.5.0, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
django settings: settings.test (from ini file)
rootdir: /Users/eric/src/, inifile: pytest.ini
plugins: django-2.9.1, pythonpath-0.7, spec-1.0.1, xdist-1.14
gw0 [54] / gw1 [54] / gw2 [54] / gw3 [54]
scheduling tests via LoadScheduling
.....................................
Changes our test output from this:
To this:
To use this module add the --spec
flag when running your test, like so:
py.test --spec
Not as flashy/useful as the others, but a nice tool to simplify adding proper python paths to run your tests.
Add python_paths
to your pytest.ini
configuration:
[pytest]
python_paths = your/path/apps your/path/libs
This plugin instantly shows failed tests instead of waiting until all tests
finish to display the output. Works nicely with spec
plugin as well.
To use it just add the --instafail
flag when running your tests, like so:
py.test --instafail
I know this is kind of a "who cares" blog post, but I'm trying to do at least one blog a month and this one popped into my head so I went for it!
Hope it was worth something to somebody, there's already a great list of plugins here but I didn't see any harm in outlining my faves.
In any case, happy holidays tomorrow everyone! :)
Four years ago I had no idea what I was doing in Web Development. Asking dumb questions in IRC all day was how I learned. Scrounging through tutorials trying to make sense of anything. Now I'm the one answering the dumb questions!
I felt like writing this because I've just realized that I now hang out in #django and actually spend most of my time giving back instead of taking. To me that's a huge achievement that deserves some attention, at least.
It's not uncommon that I leave the IRC window up on my 3rd monitor and glance at it occasionally. More and more I'm seeing people ask questions that I have no problem answering... what the hell! Without even realizing it I've transitioned from an entry-level-nobody to kinda-somebody-worth-listening-to.
When I was just getting started I vividly remember being helped by FunkyBob
multiple times... I had no idea why he was
helping me. Maybe now I'm finally starting to understand why he would helped me, but a few years ago I had no clue. I've
bought pizza/beer for a couple people and such, but that's not the right way to give back.
The real way to say thanks would be to, myself, become able to give back to the community.
I'm not sure when the switch flipped, but my best guess is recently with changes at work I am seeking out more and more ways to be proud of what I do. Instead of just getting the work done, I take pride in taking my time implementing a better solution. Not something perfect, but something I'm proud of.
I've also made horrendous fuck ups. Huge security holes, missed details, and poorly designed features. Though these seem like awful things, this where my growth seems to be happening. By being forced to confront these problems without the option to give up/change course: I am learning a fuck load.
It's regular to get stuck for hours on something simple like forgetting to pass *args, **kwargs
to a super
method,
but in those painful hours I grow and stretch my brain around the problem. When I finally understand just how stupid
I am with the small mistake, it's like taking a load off my shoulders.
Sometimes it feels like I have no idea how I'll get to the finish line on a feature. That's getting more rare. My confidence is growing that my weak points are shrinking. In the way I communicate especially.
I know this is kinda lame congratulating myself... but I'm finally getting happier doing web development, damnit! Our job is filled with negativity, set backs, and pressure--so why do we do it? Of course money is there, but that won't keep me around.
What will keep me around is this:
rpkilby: thanks for the help
xcyclist: Yes, that did it. Thanks.
shutupsquare: Hey Thanks, I never even thought to have the items have a fk to the person, perfect, thanks guys.