简体   繁体   中英

Running tests in single Python file with nose

I'm using nose 1.3.7 with Anaconda 4.1.1 (Python 3.5.2). I want to run unit tests in a single file, eg foo.py . According to the documentation I should be able to simply run:

nosetests foo.py

But when I do this, nose runs all the tests in all the files in the directory!

And if I do nose --help , the usage documentation doesn't even indicate that there is a parameter. It only shows [options].

So can I run tests in a single file using nose?

I have a standalone Python 3.4 version and nosetests foo.py runs tests only in foo.py and nosetests spam.py runs test only in spam.py .

A plain nosetests command without any option specified, runs tests in all files with names starting with the word test_ in the directory.

Here's quoting from their test discovery documentation which specifies rules for test discovery.The last line of the documentation clarifies what could be the cause for your anomaly.

Be aware that plugins and command line options can change any of those rules.

I suspect (and I may be wrong) that it has to do with how anaconda configures nose for your install.

另外,请确保您没有要测试的文件内没有nose.run()nose.main()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM