I do have several small modules where the tests are inside them and py.test
or nose
does not look for them because they do not contain test
in their filename.
How can I convince py.test
or nose
to look for tests inside all python files, recursively - '''including the ones that do not have test
in their filenames'''?
Inside the source files I do keep the standard naming convention: class testSomeName
with methods def test_some_name
.
If this is not possible, what other solution can I use to obtain the same result.
I do not want to manually create a list of all files containing the test, I want a solution that supports discovery.
You can also have a look at Nose which will discover tests without having to use a fixed file name convention.
You can bypass the regexp used to filter files in nose with the following code. Create a python module (i.e.
my_nosetests.py
)Now run
my_nosetests.py
as if you were runningnosetests
and you should have your tests running. Be aware that you are in fact loading all modules and searching for tests in them. Beware of any side effect of module loading.The documentation says that
Can you ensure that this is the case with your code?
Update
(Caveat Emptor: I haven't tried/tested this) How about using the hooks provided for collecting directories and files?
Put a file "setup.cfg" at the root of project, and it contains this two lines:
then py.test select tests from all
*.py
files. Here it's explained: pytest docswith Nose:
With py.test it's simple. Create a
conftest.py
file with this content:This will extend the collection process to create a test "Module" node for each ".py" file. Putting this into a
conftest.py
file makes it a project-specific extension which is automatically loaded if you type:For informational purposes you can also type:
to see what tests and files are collected, example output:
If needed you can also package the above
conftest.py
file as an installable plugin and make the extension available by installing the plugin. In this case you do not need anyconftest.py
file at all.