Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing options to nose in a Python test script

Tags:

python

nose

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?

like image 286
Matt W Avatar asked Aug 15 '11 20:08

Matt W


People also ask

What are nose tests Python?

nose collects tests automatically from python source files, directories and packages found in its working directory (which defaults to the current working directory).

Which command is used to run nose tests?

nose can be integrated with DocTest by using with-doctest option in athe bove command line. The result will be true if the test run is successful, or false if it fails or raises an uncaught exception. nose supports fixtures (setup and teardown methods) at the package, module, class, and test level.

Can Pytest run nose tests?

pytest has basic support for running tests written for nose.

What is Django nose?

django-nose provides all the goodness of nose in your Django tests, like: Testing just your apps by default, not all the standard ones that happen to be in INSTALLED_APPS. Running the tests in one or more specific modules (or apps, or classes, or folders, or just running a specific test)


2 Answers

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!

like image 115
dbn Avatar answered Sep 21 '22 12:09

dbn


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.

like image 40
mouad Avatar answered Sep 24 '22 12:09

mouad