Python 3.x 找不到夹具“;嘲弄者“;(pytest-mock)从tox运行时

Python 3.x 找不到夹具“;嘲弄者“;(pytest-mock)从tox运行时,python-3.x,pytest,tox,Python 3.x,Pytest,Tox,我一直在使用库来模拟pytest。当我尝试使用tox命令运行测试时,出现以下错误: 。。。 测试/测试cli.py…EEEE ... 文件/path/to/test_cli.py,第63行 def test_cli_with_init_cmd_fails_with_db_error(运行程序、模拟程序、上下文): 未找到E装置“mocker” >可用装置:缓存、capfd、capfdbinary、caplog、capsys、capsysbinary、上下文、cov、doctest_命名空间、fs

我一直在使用库来模拟pytest。当我尝试使用
tox
命令运行测试时,出现以下错误:

。。。
测试/测试cli.py…EEEE
...
文件/path/to/test_cli.py,第63行
def test_cli_with_init_cmd_fails_with_db_error(运行程序、模拟程序、上下文):
未找到E装置“mocker”
>可用装置:缓存、capfd、capfdbinary、caplog、capsys、capsysbinary、上下文、cov、doctest_命名空间、fs、monkeypatch、无封面、pytestconfig、record_属性、record_testsuite_属性、record_xml_属性、recwarn、requests_mock、runner、tmp_路径、tmp_路径工厂、tmpdir、tmpdir_工厂
>使用“pytest--fixtures[testpath]”获取关于它们的帮助。
然而,当我试图从我的venv中直接使用pytest运行测试时,一切都按预期进行

$py.test--cov esmigrate--cov报告术语缺失

...
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
文件中添加了
pytest mock
,该文件用于在venv中安装依赖项,我还将该文件添加为tox testenv的依赖项。这是我的
tox.ini
文件的内容

[tox]
envlist=py36、py37、py38、PY8
[pytest]
过滤警告=
错误::弃用警告
错误::PendingDeprecationWarning
[附件八]
最大线路长度=120
选择=B、C、E、F、W、T4、B9、B950
忽略=E203、E266、E501、W503、D1
[测试]
passenv=用户名
commands=py.test--cov-esmigrate{posargs}--cov报告项缺失
deps=-rrequirements.txt
[测试版本:第8页]
basepython=python3.8
副总裁=
薄片8
命令=
第8页:迁移率试验
requirements.txt
文件的快照

。。。
pyfakefs==4.0.2
pyparsing==2.4.7
Pyristent==0.17.3
pytest==6.1.1
pytest cov==2.10.1
pytest mock==3.3.1
Pyaml==5.3.1
...
travis ci
运行时,这也不会导致任何问题,但我想知道这里的问题是什么,我做错了什么。tox env是否无法安装pytest mock,或者“mocker”装置是否被其他东西遮挡了?

tox当前(尽管计划在(撰写本文时)当前重写中对此进行改进)如果不管理更改(如requirements.txt/setup.py)文件,则不会重新创建环境

有关相关问题,请参见我的

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



免责声明:我是当前tox维护者之一

tox很难看到环境是否发生了变化,因此您经常需要在改变依赖项后重新创建tox环境。Travis一开始是空白的,没有这个问题。因此,您需要在本地使用
--recreate
标志运行
tox
。@您可能在这里发现了一些东西。我删除了
.tox
目录,问题就消失了。看起来我可以在
tox.ini
中传入
recreate=true
,但这是个好主意吗?如果你在requirements.txt中更改了任何依赖项,那么运行“tox--recreate”是正常的。事实上,你必须。只是测试了几次,出于某种原因,我没有必要。在控制台输出中,我可以看到它正在安装库。这仍然很奇怪。所以,这对我来说似乎有点不一致。我最终使用了
--recreate
标志。因为我使用一些shell脚本来运行tox测试,所以我认为每次创建tox-env都不是问题。比编写智能脚本更容易注意到需求文件中的更改。谢谢