Skip to content

Setting a variable from the child conftest to the upper conftest #3363

Closed
@redsox10

Description

@redsox10

Hey, guys. So I have this scenario where I would really appreciate some help.

Here is a mock example:

├──parent
│  ├──test1dir
│  │  ├  conftest.py
│  │  ├  test_1.py
│  ├  conftest.py
# parent/test1dir/conftest.py
def pytest_runtest_setup(item):
    do_something(item, local_fixt())
    # --> somehow set global_var in parent conftest <--

@pytest.fixture(scope="session")
def local_fixt():
    return 123
# parent/test1dir/conftest.py
@pytest.fixture(scope="session") # same for function scoped fixtures
def session_fixt(local_fixt)
    do_something(global_var)
    do_something(local_fixt)

Reason why I don't move pytest_runtest_setup in parent conftest is that I need it to access local_fixt() and it isn't able to do that from the upper conftest file as it would solve this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs informationreporter needs to provide more information; can be closed after 2 or more weeks of inactivitytype: questiongeneral question, might be closed after 2 weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions