Why I'm getting F811 error in this code?

心不动则不痛 提交于 2020-03-06 09:27:31

问题


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):

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.

EDIT: 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.


回答1:


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



来源:https://stackoverflow.com/questions/50268284/why-im-getting-f811-error-in-this-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!