经过多次成功的测试后,pytest突然抛出此错误:
$ pytest -vvv -x --internal --oclint -n -32
============================= test session starts ==============================
platform darwin -- Python 3.7.7, pytest-5.4.1, py-1.7.0, pluggy-0.13.1 -- /usr/local/opt/python/bin/python3.7
cachedir: .pytest_cache
rootdir: /Users/pre-commit-hooks/code/pre-commit-hooks, inifile: pytest.ini
plugins: xdist-1.31.0, forked-1.1.3
ERROR: MISSING test execution (tx) nodes: please specify --tx
这是我的pytest.ini:
[pytest]
markers =
oclint: marks tests as slow (deselect with '-m "not slow"')
internal: marks tests as checking internal components. Use this if you are developing hooks
-n #
来自pytest-xdist,它是pytest的附加组件。这对我来说很奇怪,因为在travis linux构建上的pytest在最后一次迭代之前都可以正常工作。
为什么pytest要求我为测试添加--tx
?
-n -32
,则pytest将抱怨缺少--tx
选项。换句话说,-n之后的数字不能为负,而您要使用的是-n 32
。--tx
通常像这样来调用Python2.7子进程:
pytest -d --tx popen//python=python2.7
有关在pytest中使用--tx
的更多信息,请参见pytest-xdist [此标志上的文档](pytest -d --tx popen // python = python2.7)。