Upgrading pytest causes TypeError: 'NoneType' object is not callable error
Upgrading pytest causes TypeError: 'NoneType' object is not callable error
需要帮助升级 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
下个版本发布后,移除snapshot依赖和bump:
pluggy>0.6.0
适配pytest_configure
挂钩
调整您的 pytest_configure
挂钩,使其不 return 任何东西:
def configure():
from django.conf import settings
settings.configure(
...
return settings
def pytest_configure():
configure()
不要忘记在 runtests.py
中调用 configure()
函数而不是 pytest_configure()
,这样就可以了。但是,这只是一种临时解决方法,可以在 pluggy>0.6.0
发布后恢复。
通过将pytest升级到4.0.1,可以解决这个问题。最新版pytest >5.1 不兼容 python >3.4.
需要帮助升级 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
下个版本发布后,移除snapshot依赖和bump:
pluggy>0.6.0
适配pytest_configure
挂钩
调整您的 pytest_configure
挂钩,使其不 return 任何东西:
def configure():
from django.conf import settings
settings.configure(
...
return settings
def pytest_configure():
configure()
不要忘记在 runtests.py
中调用 configure()
函数而不是 pytest_configure()
,这样就可以了。但是,这只是一种临时解决方法,可以在 pluggy>0.6.0
发布后恢复。
通过将pytest升级到4.0.1,可以解决这个问题。最新版pytest >5.1 不兼容 python >3.4.