88
99import pytest
1010
11- from flake8_trio import Plugin
11+ from flake8_trio import Plugin , main
1212
1313from .test_flake8_trio import initialize_options
1414
@@ -36,10 +36,44 @@ def test_run_flake8_trio(tmp_path: Path):
3636 cwd = tmp_path ,
3737 capture_output = True ,
3838 )
39+ assert res .returncode == 1
3940 assert not res .stderr
4041 assert res .stdout == err_msg .encode ("ascii" )
4142
4243
44+ def test_systemexit_0 (
45+ tmp_path : Path , monkeypatch : pytest .MonkeyPatch , capsys : pytest .CaptureFixture [str ]
46+ ):
47+ monkeypatch .chdir (tmp_path )
48+ monkeypatch .setattr (sys , "argv" , [tmp_path / "flake8_trio" , "./example.py" ])
49+
50+ tmp_path .joinpath ("example.py" ).write_text ("" )
51+
52+ with pytest .raises (SystemExit ) as exc_info :
53+ from flake8_trio import __main__ # noqa
54+
55+ assert exc_info .value .code == 0
56+ out , err = capsys .readouterr ()
57+ assert not out
58+ assert not err
59+
60+
61+ def test_systemexit_1 (
62+ tmp_path : Path , monkeypatch : pytest .MonkeyPatch , capsys : pytest .CaptureFixture [str ]
63+ ):
64+ err_msg = _common_error_setup (tmp_path )
65+ monkeypatch .chdir (tmp_path )
66+ monkeypatch .setattr (sys , "argv" , [tmp_path / "flake8_trio" , "./example.py" ])
67+
68+ with pytest .raises (SystemExit ) as exc_info :
69+ from flake8_trio import __main__ # noqa
70+
71+ assert exc_info .value .code == 1
72+ out , err = capsys .readouterr ()
73+ assert out == err_msg
74+ assert not err
75+
76+
4377def test_run_in_git_repo (tmp_path : Path ):
4478 err_msg = _common_error_setup (tmp_path )
4579 assert subprocess .run (["git" , "init" ], cwd = tmp_path , capture_output = True )
@@ -51,6 +85,7 @@ def test_run_in_git_repo(tmp_path: Path):
5185 cwd = tmp_path ,
5286 capture_output = True ,
5387 )
88+ assert res .returncode == 1
5489 assert not res .stderr
5590 assert res .stdout == err_msg .encode ("ascii" )
5691
@@ -60,8 +95,7 @@ def test_run_no_git_repo(
6095):
6196 monkeypatch .chdir (tmp_path )
6297 monkeypatch .setattr (sys , "argv" , [tmp_path / "flake8_trio" ])
63- with pytest .raises (SystemExit ):
64- from flake8_trio import __main__ # noqa
98+ assert main () == 1
6599 out , err = capsys .readouterr ()
66100 assert err == "Doesn't seem to be a git repo; pass filenames to format.\n "
67101 assert not out
@@ -75,7 +109,7 @@ def test_run_100_autofix(
75109 monkeypatch .setattr (
76110 sys , "argv" , [tmp_path / "flake8_trio" , "--autofix" , "./example.py" ]
77111 )
78- from flake8_trio import __main__ # noqa
112+ assert main () == 1
79113
80114 out , err = capsys .readouterr ()
81115 assert out == err_msg
@@ -189,6 +223,7 @@ def test_200_from_config_flake8_internals(
189223def test_200_from_config_subprocess (tmp_path : Path ):
190224 err_msg = _test_trio200_from_config_common (tmp_path )
191225 res = subprocess .run (["flake8" ], cwd = tmp_path , capture_output = True )
226+ assert res .returncode == 1
192227 assert not res .stderr
193228 assert res .stdout == err_msg .encode ("ascii" )
194229
0 commit comments