Skip to content

Commit a887885

Browse files
fix(test): mock create_pr at save_loading import, not github_client internals
The e2e test was patching edit_python_pe.github_client._commit_and_push which is a private function deep inside create_pr. Python's patch() replaces names in the module where they are looked up, so patching the original definition site has no effect when the caller (save_loading.py) has already imported create_pr as a bound reference. The correct target is edit_python_pe.screens.save_loading.create_pr, which is the name actually resolved at call time. With the wrong patch target, create_pr executed against the real filesystem, raised an exception inside the perform_save() thread, and the screen never transitioned to SaveLoadingScreen. Also: - Add await pilot.pause() before clicking Save to allow reactive value assignments to propagate through the Textual event loop first - Simplify mock setup: one mock_create_pr replaces four separate mocks
1 parent 02a8073 commit a887885

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

tests/e2e/test_app_e2e.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,26 @@ class TestAppE2E:
1515
@pytest.mark.asyncio
1616
@patch("edit_python_pe.screens.loading.get_repo")
1717
@patch("edit_python_pe.screens.loading.fork_repo")
18-
@patch("edit_python_pe.github_client._commit_and_push")
18+
@patch("edit_python_pe.screens.save_loading.create_pr")
1919
@patch("keyring.get_password", return_value=None)
2020
@patch("keyring.set_password")
2121
async def test_full_app_flow(
2222
self,
2323
mock_set_password,
2424
mock_get_password,
25-
mock_commit_and_push,
25+
mock_create_pr,
2626
mock_fork_repo,
2727
mock_get_repo_loading,
2828
):
2929
mock_repo = MagicMock()
3030
mock_forked = MagicMock()
3131
mock_get_repo_loading.return_value = ("fake-token", mock_repo)
3232
mock_fork_repo.return_value = (tempfile.gettempdir(), mock_forked)
33-
mock_commit_and_push.return_value = (
34-
"Commit message",
35-
MagicMock(),
36-
MagicMock(),
37-
MagicMock(),
33+
mock_create_pr.return_value = (
34+
"Woohoo! john_doe-abc12345.md was saved successfully and your new PR is ready! 🎉",
35+
"https://github.com/fake/pr",
3836
)
3937

40-
# Create a mock PR
41-
mock_pr = MagicMock()
42-
mock_pr.html_url = "https://github.com/fake/pr"
43-
mock_repo.get_pulls.return_value = []
44-
mock_repo.create_pull.return_value = mock_pr
45-
4638
app = MemberApp()
4739
async with app.run_test(size=(120, 100)) as pilot:
4840
# 1. Language Screen
@@ -108,6 +100,7 @@ async def test_full_app_flow(
108100
-1
109101
].url_input.value = "https://github.com/john"
110102

103+
await pilot.pause()
111104
await pilot.click("#member-form-save")
112105

113106
# 6. Save Loading Screen — give up to 5 s for the background work

0 commit comments

Comments
 (0)