Replace @pytest.mark.order with fixtures and finalizers for E2E tests#370
Replace @pytest.mark.order with fixtures and finalizers for E2E tests#370
Conversation
Co-authored-by: jacalata <2009720+jacalata@users.noreply.github.com>
Co-authored-by: jacalata <2009720+jacalata@users.noreply.github.com>
|
|
||
| # Cleanup | ||
| try: | ||
| delete_project(parent_location) |
There was a problem hiding this comment.
if you delete the default project you do not need to also delete the child projects
|
|
||
| @pytest.mark.order(5) | ||
| def test_users_remove_from_group(self): | ||
| def test_users_remove_from_group(self, test_group): |
There was a problem hiding this comment.
We still need ordered tests because e.g. this test must take place after test_users_add_to_group
|
|
||
| @pytest.mark.order(10) | ||
| def test_wb_publish(self): | ||
| def test_wb_publish(self, test_projects): |
There was a problem hiding this comment.
the publishing test must be run after projects are created but before any get tests
|
|
||
| @pytest.mark.order(19) | ||
| def test_wb_delete(self): | ||
| def test_wb_delete(self, test_projects): |
There was a problem hiding this comment.
wb_delete and ds_delete must run after the get, extract and export tests
|
suggestion from Andy: Consider also adding a "before all" setup step that deletes all workbooks and datasources that exist on the site that match the "publishable" name pattern. Currently if you stopped the tests mid-way through execution, they'd never get deleted. |
Summary
Refactored E2E tests to use pytest fixtures with finalizers instead of
@pytest.mark.orderdecorators, addressing the issue raised in #366 about managing test order numbers manually.Problem
The E2E test suites (
online_tests.pyandlanguage_tests.py) were using@pytest.mark.orderdecorators with numeric values (1-21) to control test execution order. This approach had several limitations:pytest-orderdependencySolution
Replaced explicit ordering with pytest fixtures that handle setup and teardown automatically:
Fixtures Created (with finalizers for cleanup)
online_tests.py:
login_session()- Auto-runs before all testssite_users(login_session)- Creates/deletes test userstest_group(site_users)- Creates/deletes test grouptest_projects(login_session)- Creates/deletes test projectslanguage_tests.py:
login_all_languages()- Tests login in all languagessite_users(login_all_languages)- Creates/deletes test userstest_group(site_users)- Creates/deletes test grouptest_projects(login_all_languages)- Creates/deletes test projectsExample Conversion
Before:
After:
Changes
@pytest.mark.orderdecoratorspytest-orderdependency frompyproject.tomlBenefits
Testing
Fixes #366
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.