您当前的位置: 首页 > 

静静喜欢大白

暂无认证

  • 1浏览

    0关注

    521博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

fixture ‘xxx‘ not found

静静喜欢大白 发布时间:2020-07-07 11:30:31 ,浏览量:1

也就是定义的函数名不要是那种特殊的,比如test/testtest/test_XXX 转载 https://blog.csdn.net/weixin_44017891/article/details/103418031

代码用到了pytest,运行时出现fixture ‘xxx’ not found的问题。

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即可;
关注
打赏
1510642601
查看更多评论
立即登录/注册

微信扫码登录

0.0375s