@@ -67,8 +67,25 @@ def test_a(live_server):
67
67
result .stdout .fnmatch_lines (['*PASSED*' ])
68
68
assert result .ret == 0
69
69
70
- def test_clean_stop_live_server (self , appdir ):
71
- pytest_cov = pytest .importorskip ("pytest_cov" )
70
+ def test_clean_stop_live_server (self , appdir , monkeypatch ):
71
+ """Ensure the fixture is trying to cleanly stop the server.
72
+
73
+ Because this is tricky to test, we are checking that the _stop_cleanly() internal
74
+ function was called and reported success.
75
+ """
76
+ from pytest_flask .fixtures import LiveServer
77
+
78
+ original_stop_cleanly_func = LiveServer ._stop_cleanly
79
+
80
+ stop_cleanly_result = []
81
+
82
+ def mocked_stop_cleanly (* args , ** kwargs ):
83
+ result = original_stop_cleanly_func (* args , ** kwargs )
84
+ stop_cleanly_result .append (result )
85
+ return result
86
+
87
+ monkeypatch .setattr (LiveServer , '_stop_cleanly' , mocked_stop_cleanly )
88
+
72
89
appdir .create_test_module ('''
73
90
import pytest
74
91
try:
@@ -89,30 +106,10 @@ def index():
89
106
assert res.code == 200
90
107
assert b'got it' in res.read()
91
108
''' )
92
- result_with = appdir .runpytest ('-v' ,
93
- '--no-start-live-server' ,
94
- '--live-server-clean-stop' ,
95
- '--cov=%s' % str (appdir .tmpdir ),
96
- '--cov-report=term-missing' )
97
- result_without = appdir .runpytest ('-v' ,
98
- '--no-start-live-server' ,
99
- '--no-live-server-clean-stop' ,
100
- '--cov=%s' % str (appdir .tmpdir ),
101
- '--cov-report=term-missing' )
102
-
103
- def _get_missing (r ):
104
- for line in r .outlines :
105
- if not line .startswith ('TOTAL' ):
106
- continue
107
- # Columns: Name Stmts Miss Cover Missing
108
- return int (line .split ()[2 ])
109
- raise ValueError ("Expected a TOTAL line in the cov output" )
110
-
111
- # Read the "Missing" column (i.e. lines not covered)
112
- missing_with , missing_without = _get_missing (result_with ), _get_missing (result_without )
113
-
114
- # If the clean stop worked, the single line in the view function should be covered
115
- assert missing_with == (missing_without - 1 )
109
+ result = appdir .runpytest_inprocess ('-v' , '--no-start-live-server' ,
110
+ '--live-server-clean-stop' )
111
+ result .stdout .fnmatch_lines ('*1 passed*' )
112
+ assert stop_cleanly_result == [True ]
116
113
117
114
def test_add_endpoint_to_live_server (self , appdir ):
118
115
appdir .create_test_module ('''
0 commit comments