调试功能能函数的时候,发现终端窗口不一样。出现了新的运行模式。
终端内容如下:
D:\Anaconda\python.exe "D:\PyCharm Community Edition 2021.2.3\plugins\python-ce\helpers\pycharm\_jb_pytest_runner.py" --path D:/LSKJ/XXXX/test/1.py
Testing started at 17:10 ...
Launching pytest with arguments D:/LSKJ/XXXX/test/1.py --no-header --no-summary -q in D:\LSKJ\XXXX\test
============================= test session starts =============================
collecting ... collected 1 item
1.py::test_xxxx ERROR [100%]
test setup failed
file D:\LSKJ\XXXX\test\1.py, line 14
def test_xxxx(line_str):
E fixture 'line_str' not found
> available fixtures: anyio_backend, anyio_backend_name, anyio_backend_options, 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.
D:\LSKJ\XXXX\test\1.py:14
========================= 1 warning, 1 error in 5.77s =========================
Process finished with exit code 1
百度了下。。。
原来是进入了pycharm的测试用例模式。
解决办法:
1.检查测试函数名称 是否以 ‘test’ 开头;
2.检查测试类名称 是否以‘Test’开头,但是类中不能有init方法;
3.检查测试文件名称是否以‘test’/‘Test’开头,或者以‘test’/‘Test’结尾。