4 ms·
I'm actually interested in infrastructure around this. There is lots of documentation about how to use the various unit testing libraries out there, but what's
by pyre 15y ago
I'm actually interested in infrastructure around this. There is lots of documentation about how to use the various unit testing libraries out there, but what's the easiest way to run all of your unit tests? In Perl, the Makefile generated from Makefile.PL (or Build script generated from Build.PL) has a 'test' command that will run tests that look like t/*.t (the pattern is actually more permissive than this, but I'm not sure what the specs are beyond that being the most common case). It will automatically setup the library paths to include the code, etc, so that you don't have to manually fool around with @INC (Perl's sys.path).
Is there something similar in setup.py? If so, how does it find which files have tests to run?
edit: So there really isn't a standard Python way to 'run all unit tests?' (I'm not counting v2.7 because Python unit tests have been around a lot longer than that version has). I thought that Python was all about "there's only one way to do it." I find it a little odd that it took so long for anything like that to be included in the main distribution.
- khill 15y agoStarting in 2.7, the unittest module actually has the ability to discover tests so you can just do: python -m unittest discover The docs are here: http://docs.python.org/library/unittest.html#test-discovery http://docs.python.org/library/unittest.html#test-discovery I've actually been using both unittest and pytest for a while - I like pytest better but they are both nice tools. http://doc.pytest.org/en/latest/ http://doc.pytest.org/en/latest/ I found Tarek Ziade's book useful when learning how to best set up and execute unit tests as part of my python projects.
- warp 15y agoI really like nose (http://somethingaboutorange.com/mrl/projects/nose/ http://somethingaboutorange.com/mrl/projects/nose/). You can simply run "nosetests" in the root of your project, and it will locate and run your tests. nose will adjust sys.path to make sure your tests can find the packages they're testing. This may depend a bit on the layout you're using for your project, it has always worked for me so I have never had the need to look into HOW it works :)
- regularfry 15y agoI tend to find a bare "nosetests" catches a little more than I want it to, so I generally specify at least a test directory.