79714320

Date: 2025-07-25 07:12:05
Score: 2
Natty:
Report link

Don't do that. Python already doesn't really allow for overloaded functions (compared to other languages). And Fixtures can already be extended using different names.

@pytest.fixture
def values() -> list[int]:
    return [1,2,3]


@pytest.fixture
def new_values(values: list[int]) -> list[int]:
    return values + [4,5,6]

Another consideration of why your idea is bad... What happens when unit test are run in a different order? If your base is subclassed multiple times, how are the "values" fixture meant to be overwritten?


# Bad ideas are bad.
class Base:
    @pytest.fixture
    def values(self) -> list[int]:
        return [1,2,3]

class TestChildA(Base):
    @pytest.fixture
    def values(self, values) -> list[int]:
        return values + [4,5,6]  # does this include 7,8,9?

class TestChildB(Base):
    @pytest.fixture
    def values(self, values) -> list[int]:
        return values + [7,8,9]  # does this also include 4,5,6?
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: Spill_The_Tea