我正在尝试使用Pytest-django=3.5.1进行测试。但是,发生了以下错误:
[PytestDeprecationWarning: The `funcargnames` attribute was an alias for `fixturenames`, since pytest 2.3 - use the newer attribute instead.]错误:
> if "live_server" not in request.funcargnames:
E pytest.PytestDeprecationWarning: The `funcargnames` attribute was an alias for `fixturenames`, since pytest 2.3 - use the newer attribute instead.
>/usr/local/lib/python3.7/site-packages/pytest_django/fixtures.py:397: PytestDeprecationWarning我发现了这个问题。这似乎与我的问题相似,所以我试了一下。PytestDeprecationWarning at test setup: the funcargnames attribute was an alias for fixturenames
但这并没有解决问题。
此外,我将"funcargnames“改为"fixturenames”,但错误尚未解决。发生了同样的错误。换句话说,即使它有funcargnames或fixturenames,也会发生相同的错误。
@pytest.fixture(autouse=True, scope="function")
def _live_server_helper(request):
"""Helper to make live_server work, internal to pytest-django.
This helper will dynamically request the transactional_db fixture
for a test which uses the live_server fixture. This allows the
server and test to access the database without having to mark
this explicitly which is handy since it is usually required and
matches the Django behaviour.
The separate helper is required since live_server can not request
transactional_db directly since it is session scoped instead of
function-scoped.
It will also override settings only for the duration of the test.
"""
if "live_server" not in request.fixturenames:
return
request.getfixturevalue("transactional_db")
live_server = request.getfixturevalue("live_server")
live_server._live_server_modified_settings.enable()
request.addfinalizer(live_server._live_server_modified_settings.disable)Pytest-django能够执行而没有任何错误。对于为什么会发生这种情况,有什么建议吗?
发布于 2019-08-10 12:38:58
我是你的同事。我和你犯了同样的错误。
正如您所知,这是因为pytest-django版本并不是最新的。
您使用以下命令升级了pytest-django。
$ pip install --upgrade "pytest-django>=3.5"
但你用的是码头写作。
您必须在docker容器中升级pytest-django。
后端项目中的Dockerfile调用一个requirements-dev.txt文件。
有一个指定模块pytest-django==3.4.8。
你只需换到pytest-django==3.5.1。
发布于 2019-08-13 07:11:11
多亏了同事,我才能解决这个错误。
错误原因:当我输入一个使用docker-compose exec backend bash运行的容器时,容器中的pytest版本没有升级。
解决方案:使用docker-compose down完成之后。接下来,在不使用docker-compose build —no-cache缓存的情况下进行构建。然后pytest-django版本升级到3.5.1,并解决了错误。
https://stackoverflow.com/questions/57391619
复制相似问题