首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在从毒物库运行时找到固定的“模拟”(pytest-mocker)。

无法在从毒物库运行时找到固定的“模拟”(pytest-mocker)。
EN

Stack Overflow用户
提问于 2020-10-18 19:38:31
回答 1查看 14K关注 0票数 6

我一直在使用吡啶-模拟库来模拟pytest。当我试图使用tox命令运行测试时,我得到了以下错误:

代码语言:javascript
复制
...
tests/test_cli.py ....EEEE
...
file /path/to/test_cli.py, line 63
  def test_cli_with_init_cmd_fails_with_db_error(runner, mocker, context):
E       fixture 'mocker' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, context, cov, doctest_namespace, fs, monkeypatch, no_cover, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, requests_mock, runner, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

但是,当我试图从我的venv中直接使用pytest运行测试时,一切都如预期的那样工作。

$ py.test --cov esmigrate --cov-report term-missing

代码语言:javascript
复制
...
platform linux -- Python 3.8.5, pytest-6.1.1, py-1.9.0, pluggy-0.13.1
rootdir: /path/to/project/root, configfile: tox.ini
plugins: cov-2.10.1, pyfakefs-4.0.2, mock-3.3.1, requests-mock-1.8.0
collected 50 items                                                                                                                                                                                                

tests/test_cli.py ........                                         [ 16%]
tests/test_contexts/test_context_config.py ...                     [ 22%]
tests/test_internals/test_db_manager.py ..........                 [ 42%]
tests/test_internals/test_glob_loader.py .....                     [ 52%]
tests/test_internals/test_http_handler.py .......                  [ 66%]
tests/test_internals/test_script_parser.py .................       [100%]
...

这很奇怪,因为我在我的requirements.txt文件中添加了requirements.txt,该文件用于在venv中安装依赖项,我还将这个文件作为testenv的依赖项添加。这是我的tox.ini文件的内容。

代码语言:javascript
复制
[tox]
envlist=py36, py37, py38, flake8

[pytest]
filterwarnings =
    error::DeprecationWarning
    error::PendingDeprecationWarning

[flake8]
max-line-length = 120
select = B,C,E,F,W,T4,B9,B950
ignore = E203,E266,E501,W503,D1

[testenv]
passenv=USERNAME
commands=py.test --cov esmigrate {posargs} --cov-report term-missing
deps= -rrequirements.txt

[testenv:flake8]
basepython = python3.8
deps =
    flake8
commands =
    flake8 esmigrate tests

requirements.txt文件的快照

代码语言:javascript
复制
...
pyfakefs==4.0.2
pyparsing==2.4.7
pyrsistent==0.17.3
pytest==6.1.1
pytest-cov==2.10.1
pytest-mock==3.3.1
PyYAML==5.3.1
...

travis-ci运行时,这也不会造成任何问题,但我想知道这里的问题是什么,以及我做错了什么。是毒物-env不能安装pytest-模拟,还是“嘲弄者”夹具被其他什么东西遮蔽了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-22 22:55:50

目前的tox (虽然计划在编写当前重写时进行改进)如果文件没有管理更改(例如requirements.txt / setup.py),就不会重新创建环境。

关于一个相关的问题,您可以看到我的问题与解决办法

这里的核心问题是,如果您没有在tox.ini中直接管理tox环境依赖项,它将不会注意到更改(例如从requirements.txt中添加/删除依赖项),因此您需要使用--recreate标志运行tox以反映这些更改。

免责声明:我是目前毒物测试的维护人员之一

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64417559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档