Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override a fixture on a test module level:with "name" key_word_arg, its may not Override #12952

Open
steadyfirmness opened this issue Nov 11, 2024 · 1 comment

Comments

@steadyfirmness
Copy link

steadyfirmness commented Nov 11, 2024

description

I have some fixtures in the same test file, and I need to reload one of them as following:

@pytest.fixture()
def f1():
    return 1

@pytest.fixture(name="f1")
def f0():
    return 0

what i want

When i call “f1” its return 0 because its actually executed “f0” as following:

class TestLib:
    def test_1(self, f1):
        assert f1 == 0

pytest result

But this is fail for test

________________________________ TestLib.test_1 ________________________________

self = <lib.test.test_lib.TestLib object at 0x104b3df40>, f1 = 1

    def test_1(self, f1):
>       assert f1 == 0
E       assert 1 == 0

lib/test/test_lib.py:21: AssertionError
=========================== short test summary info ============================
FAILED lib/test/test_lib.py::TestLib::test_1 - assert 1 == 0

env

os:mac 15.0.1
python:3.12.4
pytest:8.3.2

more detail

When I change name ‘f0’ -> 'f2', as following, it works well:

@pytest.fixture()
def f1():
    return 1


@pytest.fixture(name="f1")
def f2():
    return 2

So I summarized that the overloading of fixtures in the same file is not in the order of bytecode compilation, but in the lexicographic order of functions, resulting in the phenomenon where f0 cannot reload f1 while f2 can reload f1.

I'm not sure if this is a feature or a bug

@RonnyPfannschmidt
Copy link
Member

We should error on such conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants