为什么我在此代码中收到 F811 错误? [英] Why I'm getting F811 error in this code?

查看:99
本文介绍了为什么我在此代码中收到 F811 错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将我的测试分为多个文件,并共享一个 helpers.py 和所有测试的通用功能.例如:

I have my tests divided in multiple files with share a helpers.py with common functions to all tests. For example:

helpers.py

@pytest.fixture
def settings():


test_component_a.py

from helpers import settings
@pytest.fixture
def fixture_A(settings):
@pytest.fixture
def fixture_B(settings):
def test_A(fixture_A):
def test_B(fixture_B):

我想知道为什么在 def fixture_X(settings) 的任何定义中,我都会收到错误"F811 - 从第 1 行重新定义未使用的设置".

I would like to know why in any definition of def fixture_X(settings) I'm getting the "error" F811 - redefinition of unused 'settings' from line 1.

代码运行没有任何问题,但是当我收到那个错误时,我想我在滥用某些东西.

The code is working without any issues, but as I'm getting that error, I guess I'm misusing something.

我的问题与您所说的相似.在那个问题中,OP 显然在同一级别定义了相同的功能.就我而言,helpers.py 中只有一个函数(夹具)定义.然后,fixture 被导入到另一个文件中,该文件没有任何相同功能的定义.

my question is not similar to the one you say it's similar. In that question, the OP is clearly defining the same function at the same level. In my case, there is only one definition of the function (fixture) in helpers.py. Then, the fixture is imported in another file, file which doesn't have any definition of the same function.

推荐答案

问题在于 pytest 的工作方式.当我运行 pytest 时,它会加载目录中每个文件的夹具,所以这就是它抱怨重新定义的原因

The problem is the way pytest works. When I run pytest, it will load the fixtures of every file in the directory, so that's why it complains about a redefinition

这篇关于为什么我在此代码中收到 F811 错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆