Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25262
| From | Roy Smith <roy@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Initial nose experience |
| Date | 2012-07-13 08:42 -0400 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <roy-F2685A.08422113072012@news.panix.com> (permalink) |
I've been using unittest for many years, but have steadfastly (perhaps stubbornly) avoided newfangled improvements like nose. I finally decided to take a serious look at nose. There were a few pain points I had to work through to get our existing collection of tests to run under nose. I figured I'd share them for the benefit of others who may be going through the same process. First nose won't import executable files, at least not by default. All of our test files are executable, with a "#!/usr/bin/env python" line at the top, and a "if __name__ == '__main__'" block, which does some setup and invokes unittest.main(), at the bottom. Going to the top of our source tree and typing "nosetests" was an uninspiring experience: > $ nosetests > > ---------------------------------------------------------------------- > Ran 0 tests in 0.001s > > OK The fix is either make them non-executable, or do "nosetests --exe". Next up was the the setup in the "if __name__ == '__main__'" block wasn't running. The solution here is to move all the setup to setUpModule(), where it belongs. SetUpModule() is new in Python 2.7 but it turns out it's trivial to drop that version into older systems (http://pypi.python.org/pypi/unittest2). We found a bunch of tests which require some specific setup before they could run (most blatantly, some selenium tests which depend on X11). When we were running tests semi-manually, that was not a big deal. With nose's "find them all and run them" strategy, this fails. The obvious fix is that every test needs to either set up the right environment, or be protected with the appropriate @skip decorator so it doesn't run if the environment isn't good. Lastly, nose, by default, doesn't say much. When things go wrong and you have no clue what's happening, --verbose and --debug are your friends.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Initial nose experience Roy Smith <roy@panix.com> - 2012-07-13 08:42 -0400
Re: Initial nose experience python@bdurham.com - 2012-07-15 14:02 -0400
Re: Initial nose experience Roy Smith <roy@panix.com> - 2012-07-15 14:58 -0400
Re: Initial nose experience Philipp Hagemeister <phihag@phihag.de> - 2012-07-16 12:54 +0200
Re: Initial nose experience Peter Otten <__peter__@web.de> - 2012-07-16 13:47 +0200
unittest: Improve discoverability of discover (Was: Initial nose experience) Philipp Hagemeister <phihag@phihag.de> - 2012-07-16 14:37 +0200
Re: unittest: Improve discoverability of discover Ben Finney <ben+python@benfinney.id.au> - 2012-07-16 22:45 +1000
Re: unittest: Improve discoverability of discover (Was: Initial nose experience) Philipp Hagemeister <phihag@phihag.de> - 2012-07-16 14:49 +0200
Re: Initial nose experience Roy Smith <roy@panix.com> - 2012-07-16 07:33 -0400
Re: Initial nose experience Ben Finney <ben+python@benfinney.id.au> - 2012-07-16 22:37 +1000
Re: Initial nose experience Roy Smith <roy@panix.com> - 2012-07-23 10:33 -0700
Re: Initial nose experience Roy Smith <roy@panix.com> - 2012-07-27 10:51 -0400
csiph-web