Nose doesn't just support doctest
, it actually enhances it. When you're using Nose, you can write test fixtures for your doctest
files.
If you pass --doctest-fixtures=_fixture
on the command line, Nose will go looking for a fixture file whenever it finds a doctest
file. The name of the fixture file is based on the name of the doctest
file, and is calculated by appending the doctest
fixture suffix (in other words, the value of doctest-fixtures
) to the main part of the doctest
filename, and then adding .py
to the end. For example, if Nose found a doctest
file called PID.txt
, and had been told to find doctest‑fixtures=_fixture
, it would try to find the test fixture in a file called PID_fixture.py
.
The test fixture file for a doctest
is very simple: it's just a Python module that contains a setup()
or setUp()
function, and a teardown()
or tearDown()
function. The setup
function is executed before the doctest
file, and the teardown
function is executed after the doctest
file.
The fixture operates in a different namespace from the doctest
file, so none of the variables that get defined in the fixture module are visible in the actual tests. If you want to share the variables between the fixture and the test, you'll probably want to do it by making a simple little module to hold the variables, which you can import into both the fixture and the test.
3.15.151.32