Skip to content

Commit

Permalink
Fix env-var name for parallel tox tests
Browse files Browse the repository at this point in the history
When running tests in parallel, we need to add a suffix to Django DB names to avoid clashes. This previously used `TOX_PARALLEL_ENV`, but Tox no longer sets this environment variable.

Tox does set an environment variable called `TOX_ENV_NAME`, which works for this purpose, so use that instead.
  • Loading branch information
meshy committed Feb 9, 2024
1 parent 11f613d commit 7f0e5d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pytest_django/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
def django_db_modify_db_settings_tox_suffix() -> None:
skip_if_no_django()

tox_environment = os.getenv("TOX_PARALLEL_ENV")
tox_environment = os.getenv("TOX_ENV_NAME")
if tox_environment:
# Put a suffix like _py27-django21 on tox workers
_set_suffix_to_test_databases(suffix=tox_environment)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_db_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def test_db_with_tox_suffix(
monkeypatch: pytest.MonkeyPatch,
) -> None:
"A test to check that Tox DB suffix works when running in parallel."
monkeypatch.setenv("TOX_PARALLEL_ENV", "py37-django22")
monkeypatch.setenv("TOX_ENV_NAME", "py37-django22")

django_pytester.create_test_module(
"""
Expand Down Expand Up @@ -395,7 +395,7 @@ def test_db_with_empty_tox_suffix(
monkeypatch: pytest.MonkeyPatch,
) -> None:
"A test to check that Tox DB suffix is not used when suffix would be empty."
monkeypatch.setenv("TOX_PARALLEL_ENV", "")
monkeypatch.setenv("TOX_ENV_NAME", "")

django_pytester.create_test_module(
"""
Expand Down Expand Up @@ -434,7 +434,7 @@ def test_db_with_tox_suffix(
) -> None:
"A test to check that both Tox and xdist suffixes work together."
pytest.importorskip("xdist")
monkeypatch.setenv("TOX_PARALLEL_ENV", "py37-django22")
monkeypatch.setenv("TOX_ENV_NAME", "py37-django22")

django_pytester.create_test_module(
"""
Expand Down

0 comments on commit 7f0e5d5

Please sign in to comment.