@@ -58,6 +58,53 @@ def test_a(live_server):
5858 result .stdout .fnmatch_lines (['*PASSED*' ])
5959 assert result .ret == 0
6060
61+ def test_clean_stop_live_server (self , appdir ):
62+ pytest_cov = pytest .importorskip ("pytest_cov" )
63+ appdir .create_test_module ('''
64+ import pytest
65+ try:
66+ from urllib2 import urlopen
67+ except ImportError:
68+ from urllib.request import urlopen
69+
70+ from flask import url_for
71+
72+ def test_a(live_server):
73+ @live_server.app.route('/')
74+ def index():
75+ return 'got it', 200
76+
77+ live_server.start()
78+
79+ res = urlopen(url_for('index', _external=True))
80+ assert res.code == 200
81+ assert b'got it' in res.read()
82+ ''' )
83+ result_with = appdir .runpytest ('-v' ,
84+ '--no-start-live-server' ,
85+ '--live-server-clean-stop' ,
86+ '--cov=%s' % str (appdir .tmpdir ),
87+ '--cov-report=term-missing' )
88+ result_without = appdir .runpytest ('-v' ,
89+ '--no-start-live-server' ,
90+ '--no-live-server-clean-stop' ,
91+ '--cov=%s' % str (appdir .tmpdir ),
92+ '--cov-report=term-missing' )
93+
94+ def _get_missing (r ):
95+ for line in r .outlines :
96+ if not line .startswith ('TOTAL' ):
97+ continue
98+ # Columns: Name Stmts Miss Cover Missing
99+ return int (line .split ()[2 ])
100+ raise ValueError ("Expected a TOTAL line in the cov output" )
101+
102+ # Read the "Missing" column (i.e. lines not covered)
103+ missing_with , missing_without = _get_missing (result_with ), _get_missing (result_without )
104+
105+ # If the clean stop worked, the single line in the view function should be covered
106+ assert missing_with == (missing_without - 1 )
107+
61108 def test_add_endpoint_to_live_server (self , appdir ):
62109 appdir .create_test_module ('''
63110 import pytest
0 commit comments