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

[CT-3111] [Tech debt] Create setup fixture for setting flags in unit tests #8627

Closed
1 task done
Tracked by #8269 ...
MichelleArk opened this issue Sep 12, 2023 · 2 comments · Fixed by #10190
Closed
1 task done
Tracked by #8269 ...

[CT-3111] [Tech debt] Create setup fixture for setting flags in unit tests #8627

MichelleArk opened this issue Sep 12, 2023 · 2 comments · Fixed by #10190
Assignees
Labels
tech_debt Behind-the-scenes changes, with little direct impact on end-user functionality

Comments

@MichelleArk
Copy link
Contributor

Housekeeping

  • I am a maintainer of dbt-core

Short description

Introduce a common mechanism for updating the tests and ensure that all of the unit tests can be run individually via pytest fixtures.

Acceptance criteria

  • Introduce a pytest set fixture that calls set_from_args appropriately in unit tests. This fixture should reset the global flags object as part of fixture teardown
  • Refactor existing unit test classes or methods to use this fixture instead of calling set_from_args in various patterns

Impact to Other Teams

No

Will backports be required?

No

Context

EMP_ENV_VARS = {}
ENV_VARS_TO_SUSPEND = ["DBT_CLOUD_PUBLICATIONS_DIR", "DBT_CLOUD_PUBLICATION_FILE_PATH"]

@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)
@MichelleArk MichelleArk added the tech_debt Behind-the-scenes changes, with little direct impact on end-user functionality label Sep 12, 2023
@github-actions github-actions bot changed the title [Tech debt] Create setup fixture for setting flags in unit tests [CT-3111] [Tech debt] Create setup fixture for setting flags in unit tests Sep 12, 2023
@MichelleArk
Copy link
Contributor Author

Lowering priority of this given manual fixes to several unit tests affected by this issue: #9897

@peterallenwebb
Copy link
Contributor

peterallenwebb commented May 16, 2024

@QMalcolm If you're open to it, I'd like to explore how we can combine acheive this by moving the global flags collection into InvocationContext. This seems like an even better place to start than EventManager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tech_debt Behind-the-scenes changes, with little direct impact on end-user functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants