From 207e070e0f8d93c91404982bfc8a6c027fb54edf Mon Sep 17 00:00:00 2001 From: Sviatoslav Abakumov Date: Mon, 28 Apr 2025 23:26:16 +0400 Subject: [PATCH] Fix the order of the test cases that use the live_server fixture The `live_server` fixture requires `transactional_db`, but it does so at runtime, i.e., after the `pytest_collection_modifyitems()` hook is called. --- pytest_django/plugin.py | 4 +++- tests/test_db_setup.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py index e8e629f4..c77aeac7 100644 --- a/pytest_django/plugin.py +++ b/pytest_django/plugin.py @@ -463,7 +463,9 @@ def get_order_number(test: pytest.Item) -> int: uses_db = False transactional = False fixtures = getattr(test, "fixturenames", []) - transactional = transactional or "transactional_db" in fixtures + transactional = transactional or ( + "transactional_db" in fixtures or "live_server" in fixtures + ) uses_db = uses_db or "db" in fixtures if transactional: diff --git a/tests/test_db_setup.py b/tests/test_db_setup.py index 42a7224c..3cb04dbf 100644 --- a/tests/test_db_setup.py +++ b/tests/test_db_setup.py @@ -54,6 +54,9 @@ def test_run_second_decorator(): def test_run_second_fixture(transactional_db): pass + def test_run_second_live_server_fixture(live_server): + pass + def test_run_second_reset_sequences_fixture(django_db_reset_sequences): pass @@ -107,6 +110,7 @@ def test_run_last_test_case(self): "*test_run_first_serialized_rollback_decorator*", "*test_run_second_decorator*", "*test_run_second_fixture*", + "*test_run_second_live_server_fixture*", "*test_run_second_reset_sequences_fixture*", "*test_run_second_transaction_test_case*", "*test_run_second_fixture_class*",