也就是定义的函数名不要是那种特殊的,比如test/testtest/test_XXX 转载 https://blog.csdn.net/weixin_44017891/article/details/103418031
1、在运行时出现以下问题:
___________________________ ERROR at setup of test ____________________________
file E:\xxx\main.py, line 63
def test(args, model, device, train_graphs, test_graphs, epoch):
E fixture 'args' 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.
E:\xxx\main.py:63 ============================== 1 error in 0.70s =============================== Process finished with exit code 0
2、查看原因 我这里是因为代码里用到了一个命名为test的函数名 3、解决 在看别的文章(https://www.cnblogs.com/yoyoblogs/p/11232819.html)的时候发现他们的原因是:由于pycharm中以pytest运行,它会默认把test、test_开头的.py文件当做单元测试,所以需要修改文件名。他将test_interview.py 修改为interview.py ,再次运行,成功了。
所以,我这里用到了test函数名,应该也是有问题的(具体原因是为什么,我现在也还不清楚),将其改为“tes”后代码可以正常运行。(注:在修改名字时,名字里不要包含test,例:“testset”也是不可以的)
还看到了一种解决方法(但是对于我的代码来说不管用,不知道你们怎么样): 这是因为程序是在是在测试环境下运行的, 只要将环境改成 Unittests 。 (https://blog.csdn.net/qq_42827960/article/details/85246385)
File--> Settings --> Tools --> Python Integrated Tools --> Default test runner , 将pytest改为Unittests即可;