From fa59256390663c89c897f9c47da3e4160eb6464c Mon Sep 17 00:00:00 2001 From: Dave Wilding Date: Tue, 27 Oct 2026 08:01:59 -0500 Subject: [PATCH] refactor: reset jubilant before the bad-token tests Follow-up to #208. Instead of giving the bad-token tests their own dir, have each remove jubilant from the module-wide test dir before running. The tests stay order-independent with the module's single fixture and one idiom (test_git_errors.py shares state across tests in the same dir), and no extra fixture is needed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/functional/conftest.py | 6 ------ tests/functional/test_token.py | 17 +++++++++++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py index 50d0549..3b432d1 100644 --- a/tests/functional/conftest.py +++ b/tests/functional/conftest.py @@ -11,9 +11,3 @@ def uv_run(): @pytest.fixture(scope="module") def test_dir(tmp_path_factory): yield tmp_path_factory.mktemp("functional") - - -@pytest.fixture() -def fresh_dir(tmp_path_factory): - # A dir no other test has touched. Use it in tests that assert nothing is created. - yield tmp_path_factory.mktemp("functional") diff --git a/tests/functional/test_token.py b/tests/functional/test_token.py index 1970268..9107b1c 100644 --- a/tests/functional/test_token.py +++ b/tests/functional/test_token.py @@ -1,3 +1,4 @@ +import shutil import subprocess import helpers_functional as helpers @@ -69,7 +70,9 @@ def test_invalid_repo_token(uv_run, test_dir): assert not (test_dir / "invalid").exists() -def test_bad_token_no_owner(uv_run, fresh_dir): +def test_bad_token_no_owner(uv_run, test_dir): + # An earlier test in this module may have created jubilant. + shutil.rmtree(test_dir / "jubilant", ignore_errors=True) command = [ *uv_run, "gimmegit", @@ -78,7 +81,7 @@ def test_bad_token_no_owner(uv_run, fresh_dir): ] result = subprocess.run( command, - cwd=fresh_dir, + cwd=test_dir, env=helpers.bad_token_env(), capture_output=True, text=True, @@ -93,10 +96,12 @@ def test_bad_token_no_owner(uv_run, fresh_dir): Error: GitHub rejected the token. Has the token expired? """ assert result.stderr == expected_stderr - assert not (fresh_dir / "jubilant").exists() + assert not (test_dir / "jubilant").exists() -def test_bad_token_no_upstream_owner(uv_run, fresh_dir): +def test_bad_token_no_upstream_owner(uv_run, test_dir): + # An earlier test in this module may have created jubilant. + shutil.rmtree(test_dir / "jubilant", ignore_errors=True) command = [ *uv_run, "gimmegit", @@ -105,7 +110,7 @@ def test_bad_token_no_upstream_owner(uv_run, fresh_dir): ] result = subprocess.run( command, - cwd=fresh_dir, + cwd=test_dir, env=helpers.bad_token_env(), capture_output=True, text=True, @@ -120,7 +125,7 @@ def test_bad_token_no_upstream_owner(uv_run, fresh_dir): Error: GitHub rejected the token. Has the token expired? """ assert result.stderr == expected_stderr - assert not (fresh_dir / "jubilant").exists() + assert not (test_dir / "jubilant").exists() @pytest.mark.skipif(helpers.token_unset.condition, reason=helpers.token_unset.reason)