Domanda

I am trying to run py.test on my package but it is trying to parse setup.py from the project root directory even if I tried to exclude it.

I need to collect the tests from *.py files because the test classes are included in the modules.

# setup.cfg
[pytest]
norecursedirs = .svn _build tmp* lib/third lib *.egg bin distutils setup.py
python_files = *.py

Still when I run py.test it will give me ERROR collecting setup.py which I already excluded.

/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/core.py:140: in setup
>           raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg
E           SystemExit: usage: py.test [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
E              or: py.test --help [cmd1 cmd2 ...]
E              or: py.test --help-commands
E              or: py.test cmd --help
E           
E           error: no commands supplied
È stato utile?

Soluzione

You can configure the --ignore option to your pytest.ini configuration like this maybe:

addopts = --ignore=setup.py

which should help if you are in the root directory and want py.test to ignore the setup.py file.

Altri suggerimenti

From the docs (and the name of the variable) it looks like norecursedirs only skips directories, so since setup.py is a file, putting it in norecursedirs has no effect.

http://pytest.org/latest/customize.html?highlight=norecursedirs#confval-norecursedirs

The pytest docs have the answer buried away here. Put a conftest.py file in the root directory of your project that lists the files you want pytest to ignore:

However, many projects will have a setup.py which they don’t want to be imported. Moreover, there may files only importable by a specific python version. For such cases you can dynamically define files to be ignored by listing them in a conftest.py file:


 # content of conftest.py
 import sys

 collect_ignore = ["setup.py"]

In Jedi we've solved this by adding a conftest.py file with the content of collect_ignore = ["setup.py"]. That makes it "magically" work.

IMHO py.test should make it easier to ignore setup.py, because that's a very typical use case.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top