需要帮助升级 pytest
。在 3.2.4 上一切正常,如果我移动到 3.3.x 或 3.4.x,我会收到一个我不明白的错误,我什至无法执行 -h
参数。不知道从哪里开始或为什么会这样。也许我的 virtualenv
有问题?
新鲜的虚拟环境
我确实尝试从一个全新的 virtualenv 开始,但是,我仍然遇到同样的错误。恢复到 3.2.4
修复它。
工作:
$ pytest --version
This is pytest version 3.2.4, imported from /Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pytest.py
升级到 3.3.x
$ pytest --version
This is pytest version 3.3.2, imported from /Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pytest.py
$ pytest --help
Traceback (most recent call last):
File "/Users/me/.virtualenvs/hitcount/bin/pytest", line 11, in <module>
sys.exit(main())
File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/_pytest/config.py", line 59, in main
return config.hook.pytest_cmdline_main(config=config)
File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pluggy/__init__.py", line 617, in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pluggy/__init__.py", line 222, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pluggy/__init__.py", line 216, in <lambda>
firstresult=hook.spec_opts.get('firstresult'),
File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pluggy/callers.py", line 201, in _multicall
return outcome.get_result()
File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pluggy/callers.py", line 76, in get_result
raise ex[1].with_traceback(ex[2])
File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pluggy/callers.py", line 180, in _multicall
res = hook_impl.function(*args)
File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/_pytest/helpconfig.py", line 102, in pytest_cmdline_main
config._do_configure()
File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/_pytest/config.py", line 921, in _do_configure
self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pluggy/__init__.py", line 630, in call_historic
proc(x)
TypeError: 'NoneType' object is not callable
来源:
这是我维护的一个开源项目:https://github.com/thornomad/django-hitcount
最佳答案
您遇到的错误不在 pytest
中,而是在它所基于的插件库中,pluggy
。该错误已在 2 个月前修复 ( see this commit ),但不幸的是,当前最新版本的 pluggy
(0.6.0) 不包含此修复。
因此你有两种可能性:
依赖pluggy
快照
这是侵入性最小的一种。 pytest
不需要严格的 pluggy
版本,所以只需要开发版本直到下一个 pluggy
版本:
# tests/requirements.txt
coverage==4.5.1
flake8==2.5.4
mock==2.0.0
pytest==3.4.2
pytest-django==3.1.2
selenium==3.10.0
tox==2.9.1
# add some meaningful explanation here
# so you don't forget why you need this particular snapshot of pluggy
git+https://github.com/pytest-dev/pluggy@dcde058f93a509b9c39409fca02100e43bb43485
一旦发布下一个版本,移除快照依赖和bump:
pluggy>0.6.0
适配pytest_configure
钩子(Hook)
调整你的 pytest_configure
钩子(Hook),让它不返回任何东西:
def configure():
from django.conf import settings
settings.configure(
...
return settings
def pytest_configure():
configure()
不要忘记调用 runtests.py
中的 configure()
函数,而不是 pytest_configure()
去。但是,这只是一种临时解决方法,可以在 pluggy>0.6.0
发布后恢复。
关于python - 升级pytest导致TypeError : 'NoneType' object is not callable error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49222352/