Skip to content

Instantly share code, notes, and snippets.

@volgoweb
Forked from shaypal5/conftest.py
Created February 2, 2022 07:53

Revisions

  1. @shaypal5 shaypal5 revised this gist Oct 6, 2020. No changes.
  2. @shaypal5 shaypal5 created this gist Oct 6, 2020.
    22 changes: 22 additions & 0 deletions conftest.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    import os
    import pytest

    try:
    from.temp_env_var import TEMP_ENV_VARS, ENV_VARS_TO_SUSPEND
    except ImportError:
    TEMP_ENV_VARS = {}
    ENV_VARS_TO_SUSPEND = []


    @pytest.fixture(scope="session", autouse=True)
    def tests_setup_and_teardown():
    # Will be executed before the first test
    old_environ = dict(os.environ)
    os.environ.update(TEMP_ENV_VARS)
    for env_var in ENV_VARS_TO_SUSPEND:
    os.environ.pop(env_var, default=None)

    yield
    # Will be executed after the last test
    os.environ.clear()
    os.environ.update(old_environ)