具有以下文件配置:
### contents of my_module.py
def testtime_func(path):
pass
### contents of my_test.py
from my_module import testtime_func
def test():
testtime_func(1)
assert True
命令pytest my_test.py
失败:
============================================================= test session starts =============================================================
platform linux -- Python 3.6.7, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
rootdir: /home/zaccharie/workspace/tests/pytest_failing
plugins: typeguard-2.7.1
collected 2 items
my_test.py E. [100%]
=================================================================== ERRORS ====================================================================
_______________________________________________________ ERROR at setup of testtime_func _______________________________________________________
file /home/zaccharie/workspace/tests/pytest_failing/my_module.py, line 1
def testtime_func(path):
E fixture 'path' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.
/home/zaccharie/workspace/tests/pytest_failing/my_module.py:1
=========================================================== short test summary info ===========================================================
ERROR my_test.py::testtime_func
========================================================= 1 passed, 1 error in 0.01s ==========================================================
我不明白为什么pytest
在指定路径之外寻找测试功能(但已导入)。
我也通过配置testpaths尝试了皮带和吊带,但无济于事。
Pytest首先找到由路径等指定的测试文件,然后导入它们并查找与configured naming conventions相匹配的任何函数或类。