Skip to content

Create RuntimeConfig fixture#10242

Merged
QMalcolm merged 9 commits intomainfrom
qmalcolm--10000-create-runtime-config-fixture
May 31, 2024
Merged

Create RuntimeConfig fixture#10242
QMalcolm merged 9 commits intomainfrom
qmalcolm--10000-create-runtime-config-fixture

Conversation

@QMalcolm
Copy link
Contributor

@QMalcolm QMalcolm commented May 29, 2024

resolves #10000

Problem

We haven't had a RuntimeConfig pytest fixture for unit tests. This made writing a lot of unit tests hard because a lot of our code depends on a RuntimeConfig existing.

Solution

Create a runtime_config pytest fixture and use it to rewrite some existing tests 🙂

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX
  • This PR includes type annotations for new and modified functions

@QMalcolm QMalcolm added the Skip Changelog Skips GHA to check for changelog file label May 29, 2024
@cla-bot cla-bot bot added the cla:yes label May 29, 2024
QMalcolm added 3 commits May 29, 2024 15:35
Previously in `test_unsupported_version_extra_config` and
`test_archive_not_allowed` we were checking for `DbtProjectError`. This
worked because `ProjectContractError` is a subclass of `DbtProjectError`.
However, if we check for `DbtProjectError` in these tests than, some tangential
failure which raises a `DbtProejctError` type error would go undetected. As
we plan on modifying these tests to be pytest in the coming commits, we want to
ensure that the tests are succeeding for the right reason.
@QMalcolm QMalcolm force-pushed the qmalcolm--10000-create-runtime-config-fixture branch from b4cad77 to 5215807 Compare May 29, 2024 22:36
@codecov
Copy link

codecov bot commented May 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.67%. Comparing base (eb71ad9) to head (ce46f02).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10242      +/-   ##
==========================================
+ Coverage   88.59%   88.67%   +0.08%     
==========================================
  Files         180      180              
  Lines       22435    22477      +42     
==========================================
+ Hits        19876    19932      +56     
+ Misses       2559     2545      -14     
Flag Coverage Δ
integration 85.93% <ø> (-0.03%) ⬇️
unit 63.30% <ø> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@QMalcolm QMalcolm force-pushed the qmalcolm--10000-create-runtime-config-fixture branch 2 times, most recently from 630edea to f8a4064 Compare May 30, 2024 00:29
QMalcolm added 6 commits May 29, 2024 17:33
…ng fixtures

While converting `test_from_parts` I noticed the comment
>  TODO(jeb): Adapters must assert that quoting is populated?

This led me to beleive that `quoting` shouldn't be "fully" realized
in our project fixture unless we're saying that it's gone through
adapter instantiation. Thus I update the `quoting` on our project
fixture to be an empty dict. This change affected `test__str__` in
`test_project.py` which we thus needed to update accordingly.
…est_project

We've done two things in this commit, which arguably _should_ have been done in
two commits. First we moved the version specifier tests from `test_runtime.py::TestRuntimeConfig`
to `test_project.py::TestGetRequiredVersion` this is because what is really being
tested is the `_get_required_version` method. Doing it via `RuntimeConfig.from_parts` method
made actually testing it a lot harder as it requires setting up more of the world and
running with a _full_ project config dict.

The second thing we did was convert it from the old unittest implementation to a pytest
implementation. This saves us from having to create most of the world as we were doing
previously in these tests.

Of note, I did not move the test `test_unsupported_version_range_bad_config`. This test
is a bit different from the rest of the version specifier tests. It was introduced in
[1eb5857](1eb5857)
of [#2726](#2726) to resolve [#2638](#2638).
The focus of #2726 was to ensure the version specifier checks were run _before_ the validation
of the `dbt_project.yml`. Thus what this test is actually testing for is order of
operations at parse time. As such, this is really more a _functional_ test than a
unit test. In the next commit we'll get this test moved (and renamed)
We do already have tests that ensure "extra" keys aren't allowed in
the dbt_project.yaml. This test is different because it's checking that
a specific key, `archive`, isn't allowed. We do this because at one point
in time `archive` _was_ an allowed key. Specifically, we stopped allowing
`archive` in dbt-core 0.15.0 via commit [f26948d](f26948d).
Given that it's been 5 years and a major version, we could probably remove
this test, but let's keep it around unless we start supporting `archive` again.
@QMalcolm QMalcolm force-pushed the qmalcolm--10000-create-runtime-config-fixture branch from f8a4064 to ce46f02 Compare May 30, 2024 00:36
@QMalcolm QMalcolm marked this pull request as ready for review May 30, 2024 00:38
@QMalcolm QMalcolm requested a review from a team as a code owner May 30, 2024 00:38
str(config)


class TestRuntimeConfigOLD(BaseConfigTest):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class, TestRuntimeConfigOLD, goes away in a later commit (ce46f02) after we've moved all the tests it contains.

@QMalcolm QMalcolm merged commit a34267f into main May 31, 2024
@QMalcolm QMalcolm deleted the qmalcolm--10000-create-runtime-config-fixture branch May 31, 2024 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla:yes Skip Changelog Skips GHA to check for changelog file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create RuntimeConfig fixture and refactor the current test to use it

3 participants