Passing options to nose in a Python test script

让人想犯罪 __ 提交于 2019-12-18 03:25:02

问题


Rather than running my nose tests from the command line, I'm using a test runner that sets up a few things for all the tests, including a connection to a local test instance of MongoDB. The documentation for nose only seems to indicate how to pass options through the command line or a configuration file located in your home directory. Is there a way to pass options, such as --with-xunit when using a script to run your tests?


回答1:


Like this:

import nose

argv = ['fake', '--with-xunit']
nose.main(argv=argv)

The "fake" argument must be added to stand in for the executable name, as described in dbw's answer.




回答2:


Nose does something sneaky with the first argument, so it is not parsed. My nose wrapper does something like this:

import nose
import sys

argv = sys.argv[:]
argv.insert(1, "--with-xunit")
nose.main(argv=argv)

As a bonus, this allows the clients of your program to use Nose arguments to control its behavior!



来源:https://stackoverflow.com/questions/7070501/passing-options-to-nose-in-a-python-test-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!