I've just started using pytest with PyCharm (version 2022.1.4) and am stumped on a pytest fixture / PyCharm code completion issue.
In this example, I have two modules a.py
and b.py
which are part of the same project. There is a fixture in a.py
and another fixture in b.py
both of which use the same name but do different things. The code completion / intellisense from PyCharm when I'm in b.py
is giving me the class variable defined in a.py
instead of what's defined in b.py
.
It's my understanding that fixtures are not re-used throughout the project and are local to the module it's defined in.
What am I missing here? Can fixture names not be reused in other modules?
a.py
import pytest
class Person_A:
name = "A"
@pytest.fixture()
def person():
return Person_A()
def test_name(person):
assert person.name == "A"
b.py
import pytest
class Person_B:
age = 80
@pytest.fixture()
def person():
return Person_B()
def test_age(person):
assert person. # <---- The code completion here after typing the "." only shows "name" from a.py
# also, hovering over the "person" parameter passed in shows that it's from a.py
In the code above I define a person
fixture in both a.py
and b.py
. However, in b.py
when I go and use the fixture in the function test_age(person)
the code completion only gives me the ability to select 'name' (which is only defined in a.py
). Also, in b.py
if I hover over the person
parameter passed in to the test_age
function it's showing that it's from a.py