Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make tests so that will not be impacted by any existing config files #2177

Closed
@JohnVillalovos

Description

@JohnVillalovos

Capturing the comments that were left by @nejch in #2173

Thanks for the catch @JohnVillalovos! We already have some scaffolding for mocking/prepping a clean config environment but perhaps it was not broad enough in where we placed it. It seems we should have a clean environment for all tests by adding that to the root tests/conftest.py e.g.:

  1. Move this mock_clean_env fixture to the root conftest with autouse=True - no test ever should break from a user-supplied PYTHON_GITLAB_CFG:

    @pytest.fixture
    def mock_clean_env(monkeypatch):
    monkeypatch.delenv("PYTHON_GITLAB_CFG", raising=False)

  2. Move more logic to that fixture that we already use to ensure an empty list of default files - same here, no test ever should be affected by presence of local files:

    with monkeypatch.context() as m:
    m.setattr(config, "_DEFAULT_FILES", [])

  3. In any test that does specifically need that, override it again if needed (I think we mostly don't, as we explicitly define things) like we already do here:

    monkeypatch.setenv("PYTHON_GITLAB_CFG", "/some/path")

More approaches are discussed here https://stackoverflow.com/questions/38748257/disable-autouse-fixtures-on-specific-pytest-marks in case the simple override is not enough.

WDYT? This would then also be more local/CI-agnostic and consistent across all runs and we can stop worrying about config even before we hit CI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    testFor issues or missing tests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions