fixture 'xxx' not found

代码用到了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、解决
<1> 在看别的文章(https://www.cnblogs.com/yoyoblogs/p/11232819.html)的时候发现他们的原因是:由于pycharm中以pytest运行,它会默认把test、test_开头的.py文件当做单元测试,所以需要修改文件名。他将test_interview.py 修改为interview.py ,再次运行,成功了。

所以,我这里用到了test函数名,应该也是有问题的(具体原因是为什么,我现在也还不清楚),将其改为“tes”后代码可以正常运行。(注:在修改名字时,名字里不要包含test,例:“testset”也是不可以的)
在这里插入图片描述

<2>还看到了一种解决方法(但是对于我的代码来说不管用,不知道你们怎么样):
这是因为程序是在是在测试环境下运行的, 只要将环境改成 Unittests 。
(https://blog.csdn.net/qq_42827960/article/details/85246385)

File--> Settings --> Tools --> Python Integrated Tools --> Default test runner , 将pytest改为Unittests即可;

  • 36
    点赞
  • 52
    收藏
    觉得还不错? 一键收藏
  • 16
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值