[英]ERROR collecting setup.py while trying to run py.test?
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. 我试图在我的包上运行
py.test
,但它试图从项目根目录解析setup.py
,即使我试图排除它。
I need to collect the tests from *.py files because the test classes are included in the modules. 我需要从* .py文件中收集测试,因为测试类包含在模块中。
# 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. 还是当我运行
py.test
它会给我ERROR collecting setup.py
我已经排除的ERROR collecting setup.py
。
/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
You can configure the --ignore option to your pytest.ini configuration like this maybe: 您可以为pytest.ini配置配置--ignore选项,如下所示:
addopts = --ignore=setup.py
which should help if you are in the root directory and want py.test to ignore the setup.py file. 如果你在根目录并希望py.test忽略setup.py文件,这应该会有所帮助。
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. 从文档(和变量的名称)看起来
norecursedirs
只跳过目录,所以由于setup.py
是一个文件,将它放在norecursedirs
中没有任何效果。
http://pytest.org/latest/customize.html?highlight=norecursedirs#confval-norecursedirs http://pytest.org/latest/customize.html?highlight=norecursedirs#confval-norecursedirs
The pytest docs have the answer buried away here. pytest文档将答案埋没在这里。 Put a
conftest.py
file in the root directory of your project that lists the files you want pytest
to ignore: 将
conftest.py
文件放在项目的根目录中,该目录列出了您希望pytest
忽略的文件:
However, many projects will have a setup.py which they don't want to be imported.
但是,许多项目都有一个不想导入的setup.py。 Moreover, there may files only importable by a specific python version.
此外,可能只有特定python版本可以导入的文件。 For such cases you can dynamically define files to be ignored by listing them in a conftest.py file:
对于这种情况,您可以通过将它们列在conftest.py文件中来动态定义要忽略的文件:
# 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"]
. 在Jedi中,我们通过添加
conftest.py
文件解决了这个问题,其中包含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. 恕我直言py.test应该更容易忽略
setup.py
,因为这是一个非常典型的用例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.