Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6008 +/- ##
==========================================
- Coverage 86.87% 86.85% -0.03%
==========================================
Files 419 419
Lines 25980 26000 +20
Branches 2827 2829 +2
==========================================
+ Hits 22570 22581 +11
- Misses 2789 2806 +17
+ Partials 621 613 -8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| "timeout", | ||
| "--signal=INT", | ||
| "360", |
There was a problem hiding this comment.
We don't need to timeout anymore, tests don't get stuck
| "-n", | ||
| "4", |
There was a problem hiding this comment.
This flag runs the tests with 4 workers
|
|
||
|
|
||
| def load_default_dsr_policies() -> None: | ||
| def load_default_dsr_policies(session: Session) -> None: |
There was a problem hiding this comment.
Made this synchronous to avoid DB locking in the FastAPI lifespan function
|
|
||
| @pytest.fixture(scope="function") | ||
| @pytest.mark.asyncio | ||
| async def fideslang_resources( |
There was a problem hiding this comment.
This fixture creates the data needed for some CLI tests. This makes it so we're not dependent on the side-effects of other tests
| ApplicationConfig.update_config_set(db, CONFIG) | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True, scope="function") |
There was a problem hiding this comment.
Removed autouse to make it easier to see which fixtures a test is dependent on
| @pytest.fixture(scope="function") | ||
| def default_data_categories(db: Session): | ||
| for data_category in DEFAULT_TAXONOMY.data_category: | ||
| if ( | ||
| DataCategoryDbModel.get_by(db, field="name", value=data_category.name) | ||
| is None | ||
| ): | ||
| DataCategoryDbModel.create( | ||
| db=db, data=data_category.model_dump(mode="json") | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def default_data_uses(db: Session): | ||
| for data_use in DEFAULT_TAXONOMY.data_use: | ||
| if DataUse.get_by(db, field="name", value=data_use.name) is None: | ||
| DataUse.create(db=db, data=data_use.model_dump(mode="json")) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def default_organization(db: Session): | ||
| load_default_organization(db) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def default_taxonomy(db: Session): | ||
| load_default_taxonomy(db) |
There was a problem hiding this comment.
Saving some time by not creating these fixtures unless they're needed by a test
|
|
||
|
|
||
| @pytest.fixture(scope="function", autouse=True) | ||
| async def clear_db_tables(db, async_session): |
There was a problem hiding this comment.
Clears all database tables after each test run. This also closes any open DB connections (sync or async) that may linger after a test
| def pytest_configure_node(node): | ||
| """Pytest hook automatically called for each xdist worker node configuration.""" | ||
| if hasattr(node, "workerinput") and node.workerinput: | ||
| worker_id = node.workerinput["workerid"] | ||
| print( | ||
| f"[Configure Node] Configuring database and config for worker {worker_id}..." | ||
| ) | ||
|
|
||
| os.environ["FIDES__DATABASE__TEST_DB"] = f"fides_test_{worker_id}" | ||
|
|
||
| get_config.cache_clear() | ||
| fides_config = get_config() | ||
| sync_db_uri = fides_config.database.sqlalchemy_test_database_uri | ||
| async_db_uri = fides_config.database.async_database_uri | ||
|
|
||
| # Log connection strings | ||
| print( | ||
| f"[Configure Node] Sync DB URI: {sync_db_uri} Async DB URI: {async_db_uri}" | ||
| ) | ||
| else: | ||
| print( | ||
| "[Configure Node] Skipping DB setup/config update on single node or non-xdist run." | ||
| ) |
There was a problem hiding this comment.
This is what allows for parallel test execution. This runs before any of the tests, and allows each worker to specify the env var for its own test DB. Each worker then creates its own database at the beginning of the test run that it uses for all of its tests.
| pytest-env==0.7.0 | ||
| pytest-mock==3.14.0 | ||
| pytest-rerunfailures==14.0 | ||
| pytest-xdist==3.6.1 |
There was a problem hiding this comment.
For parallel test execution ⚡
JadeCara
left a comment
There was a problem hiding this comment.
Really nice work! Very exciting changes!
| configure_db(CONFIG.database.sync_database_uri) | ||
| with get_autoclose_db_session() as session: | ||
| seed_db(session) | ||
| if CONFIG.database.load_samples: | ||
| async with get_async_autoclose_db_session() as async_session: | ||
| await seed.load_samples(async_session) |
| return FidesDataCategory | ||
|
|
||
|
|
||
| # TODO: Move away from using this, it conflicts with the DataCategory model |
There was a problem hiding this comment.
Do we have a story to follow up on this?
|
|
||
| @pytest.mark.unit | ||
| class TestFilterDataCategories: | ||
| @pytest.mark.skip("this times out on CI") |
|
|
||
|
|
||
| class TestDB: | ||
| @pytest.mark.skip( |
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def monkeysession(): |
fides
|
||||||||||||||||||||||||||||||
| Project |
fides
|
| Branch Review |
main
|
| Run status |
|
| Run duration | 00m 53s |
| Commit |
|
| Committer | Adrian Galvan |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
5
|
Upgrade your plan to view test results. | |
| View all changes introduced in this branch ↗︎ | |
Closes LJ-526
Description Of Changes
General cleanup of tests and fixtures. Tests no longer have implied dependencies or required execution order. This means tests can run independently and more importantly in parallel.
clear_db_tablesfunction-scoped fixture to reset the DB state at the end of each test.dbandasync_sessionfixtures defined at the root levelconftest.py.migrate_dbto only handle DB migration. Side effects of creating seed and sample data were moved to separate functions.pytest-xdistand enabled parallel test execution with 4 workersops-unit-apifrom 14 minutes to 4.5 minutesops-unit-non-apifrom 15 minutes to 4.5 minutesSteps to Confirm
Pre-Merge Checklist
CHANGELOG.mdupdatedmaindowngrade()migration is correct and works