Skip to content

feat(test-tools): Add run_tasks fixture#85

Merged
khvn26 merged 6 commits into
mainfrom
feat/test-tools-run-tasks-fixture
Jun 12, 2025
Merged

feat(test-tools): Add run_tasks fixture#85
khvn26 merged 6 commits into
mainfrom
feat/test-tools-run-tasks-fixture

Conversation

@khvn26

@khvn26 khvn26 commented Jun 5, 2025

Copy link
Copy Markdown
Member

This PR is a PoC for the run_tasks fixture.

By default, we run tasks synchronously in tests. However, in order to test complex workflows that require asynchronous processing, we need a way to schedule and run tasks as they would've been run with TASK_PROCESSOR_MODE enabled. The new fixture makes sure TASK_RUN_METHOD is set to TASK_PROCESSOR in the context of a test using it, and allows to run a pre-determined number of tasks to verify their operation.

Usage:

def test_logic_involving_async_processing(run_tasks: RunTasksFixture) -> None:
   # When
   # code scheduling a task is called
   my_logic()

   # Then
   task_runs = run_tasks(num_tasks=1)

   # The task was failed
   assert task_runs[0].result == "FAILURE"

We can probably pack the assertion logic in a fixture as well to allow something like an AssertTaskRunFixture:

def test_logic_involving_async_processing(assert_task_run: AssertTaskRunFixture) -> None:
   # When
   my_logic()

   # Then
   assert_task_run("my_module.my_task", "FAILURE")

@khvn26 khvn26 requested a review from a team as a code owner June 5, 2025 16:44
@khvn26 khvn26 requested review from Zaimwa9 and removed request for a team June 5, 2025 16:44
@codecov-commenter

codecov-commenter commented Jun 5, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.41860% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.08%. Comparing base (abec78b) to head (aea8a76).
⚠️ Report is 76 commits behind head on main.

Files with missing lines Patch % Lines
src/common/test_tools/plugin.py 50.00% 8 Missing ⚠️
src/common/test_tools/types.py 0.00% 3 Missing ⚠️

❌ Your patch status has failed because the patch coverage (74.41%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #85      +/-   ##
==========================================
- Coverage   94.42%   94.08%   -0.35%     
==========================================
  Files          74       73       -1     
  Lines        2208     2232      +24     
==========================================
+ Hits         2085     2100      +15     
- Misses        123      132       +9     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/common/test_tools/plugin.py
@khvn26 khvn26 merged commit 9bd0855 into main Jun 12, 2025
4 checks passed
This was referenced Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants