Skip to content

Commit 83ec79f

Browse files
frenzymadnessclaude
andcommitted
Improve e2e tests: use tmp_path and pytest.raises
The two --rpm-dir tests patched os.path.isdir and glob.glob directly, coupling the tests to implementation internals (the fact that the code uses os.path.isdir rather than pathlib, for example). Replace the mocked filesystem calls with real filesystem state: - test_cli_rpm_dir_not_found: pass tmp_path / 'nonexistent', which is a genuinely non-existent directory with no patching needed. - test_cli_rpm_dir_no_rpms: pass the empty tmp_path directly. Replace the try/except SystemExit pattern with pytest.raises(SystemExit) in all three tests, which is the idiomatic pytest style. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent f2079c2 commit 83ec79f

1 file changed

Lines changed: 18 additions & 30 deletions

File tree

tests/e2e/test_cli_rpm_mode.py

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,45 @@
44
Tests the command-line interface with --rpms and --rpm-dir options.
55
"""
66

7+
import pytest
78
from unittest.mock import patch
89
from fedora_revdep_check import main
910

1011

1112
class TestCLIRPMMode:
1213
"""Test CLI with --rpms option."""
1314

14-
def test_cli_rpm_dir_not_found(self, capsys):
15+
def test_cli_rpm_dir_not_found(self, tmp_path, capsys):
1516
"""Test CLI with --rpm-dir when directory doesn't exist."""
16-
test_args = ['fedora-revdep-check', '--rpm-dir', '/nonexistent']
17+
nonexistent = tmp_path / 'nonexistent'
18+
test_args = ['fedora-revdep-check', '--rpm-dir', str(nonexistent)]
1719

18-
with patch('sys.argv', test_args), \
19-
patch('os.path.isdir', return_value=False):
20-
21-
exit_code = 0
22-
try:
20+
with patch('sys.argv', test_args):
21+
with pytest.raises(SystemExit) as excinfo:
2322
main()
24-
except SystemExit as e:
25-
exit_code = e.code
2623

27-
assert exit_code == 1
28-
captured = capsys.readouterr()
29-
assert 'Directory not found' in captured.err
24+
assert excinfo.value.code == 1
25+
captured = capsys.readouterr()
26+
assert 'Directory not found' in captured.err
3027

31-
def test_cli_rpm_dir_no_rpms(self, capsys):
28+
def test_cli_rpm_dir_no_rpms(self, tmp_path, capsys):
3229
"""Test CLI with --rpm-dir when directory has no RPM files."""
33-
test_args = ['fedora-revdep-check', '--rpm-dir', '/tmp/empty']
30+
test_args = ['fedora-revdep-check', '--rpm-dir', str(tmp_path)]
3431

35-
with patch('sys.argv', test_args), \
36-
patch('os.path.isdir', return_value=True), \
37-
patch('glob.glob', return_value=[]):
38-
39-
exit_code = 0
40-
try:
32+
with patch('sys.argv', test_args):
33+
with pytest.raises(SystemExit) as excinfo:
4134
main()
42-
except SystemExit as e:
43-
exit_code = e.code
4435

45-
assert exit_code == 1
46-
captured = capsys.readouterr()
47-
assert 'No .rpm files found' in captured.err
36+
assert excinfo.value.code == 1
37+
captured = capsys.readouterr()
38+
assert 'No .rpm files found' in captured.err
4839

4940
def test_cli_missing_arguments(self, capsys):
5041
"""Test CLI with no arguments shows error."""
5142
test_args = ['fedora-revdep-check']
5243

5344
with patch('sys.argv', test_args):
54-
exit_code = 0
55-
try:
45+
with pytest.raises(SystemExit) as excinfo:
5646
main()
57-
except SystemExit as e:
58-
exit_code = e.code
5947

60-
assert exit_code == 2 # argparse error
48+
assert excinfo.value.code == 2 # argparse error

0 commit comments

Comments
 (0)