gpt4 book ai didi

python - Pytest:KeyError:WindowsPath ('D:/Local_Project_Directory/Lib/site-packages/matplotlib/testing/conftest.py')

转载 作者:行者123 更新时间:2023-12-01 06:25:34 25 4
gpt4 key购买 nike

我是 Pytest 的新手,一般都在开发。我正在尝试运行一个简单的 pytest 断言,但是收到错误:

KeyError: WindowsPath('D:/ireact-tester-if/Lib/site-packages/matplotlib/testing/conftest.py')

During handling of the above exception, another exception occurred:
lib\site-packages\py\_path\common.py:383: in visit
for x in Visitor(fil, rec, ignore, bf, sort).gen(self):
lib\site-packages\py\_path\common.py:435: in gen
for p in self.gen(subdir):
lib\site-packages\py\_path\common.py:435: in gen
for p in self.gen(subdir):
lib\site-packages\py\_path\common.py:435: in gen
for p in self.gen(subdir):
lib\site-packages\py\_path\common.py:424: in gen
dirs = self.optsort([p for p in entries
lib\site-packages\py\_path\common.py:425: in <listcomp>
if p.check(dir=1) and (rec is None or rec(p))])
lib\site-packages\_pytest\main.py:626: in _recurse
ihook = self.gethookproxy(dirpath)
lib\site-packages\_pytest\main.py:445: in gethookproxy
my_conftestmodules = pm._getconftestmodules(fspath)
lib\site-packages\_pytest\config\__init__.py:437: in _getconftestmodules
mod = self._importconftest(conftestpath)
lib\site-packages\_pytest\config\__init__.py:484: in _importconftest
self.consider_conftest(mod)
lib\site-packages\_pytest\config\__init__.py:537: in consider_conftest
self.register(conftestmodule, name=conftestmodule.__file__)
lib\site-packages\_pytest\config\__init__.py:343: in register
ret = super().register(plugin, name)
lib\site-packages\pluggy\manager.py:127: in register
hook._maybe_apply_history(hookimpl)
lib\site-packages\pluggy\hooks.py:333: in _maybe_apply_history
res = self._hookexec(self, [method], kwargs)
lib\site-packages\pluggy\manager.py:93: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
lib\site-packages\pluggy\manager.py:87: in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
Lib\site-packages\matplotlib\testing\conftest.py:10: in pytest_configure
matplotlib._init_tests()
Lib\site-packages\matplotlib\__init__.py:1361: in _init_tests
faulthandler.enable()
E AttributeError: 'LogFile' object has no attribute 'fileno'

我尝试运行的 pytest 脚本很简单:

import pytest

@pytest.fixture(scope='module')
def nominal():
x=1
y=2
yield x, y

def test_one(nominal):
assert nominal[1] > nominal[0]

我正在使用 pyenv 和 python 3.6.8,我安装了 pytest 及其所有相关库。我不知道为什么会发生这种情况。有人知道如何解决这个问题吗?

最佳答案

您可以指定 pytest 将使用的多个测试目录:

pytest <my_test_directory1> <my_test_directory2> <my_test_directory3>

替换<my_test_directory1>与第一个目录和 <my_test_directory2>第二个目录包含您的测试。

关于python - Pytest:KeyError:WindowsPath ('D:/Local_Project_Directory/Lib/site-packages/matplotlib/testing/conftest.py'),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60165243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com