Skip to content

Commit 7fbc736

Browse files
committed
Change --live-server-scope to an ini option
This was brought up in #113, but was missed.
1 parent 5941e8e commit 7fbc736

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

docs/features.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,17 @@ in your project's ``pytest.ini`` file)::
188188
``request_ctx`` - request context
189189
`````````````````````````````````
190190

191-
``--live-server-scope`` - set the scope of the live server
191+
``live_server_scope`` - set the scope of the live server
192192
``````````````````````````````````````````````````````````````````
193193

194-
By default, the server will be scoped to `session`. In some cases, you may want
195-
it to be fixed to a different scope. You can use ``--live-server-scope`` (for example,
196-
in your project's ``pytest.ini`` file)::
194+
By default, the server will be scoped to ``session`` for performance reasons, however
195+
if your server has global state and you want better test isolation, you can use the
196+
``live_server_scope`` ini option to change the fixture scope:
197+
198+
.. code-block:: ini
197199
198200
[pytest]
199-
addopts = --live-server-scope=function
201+
live_server_scope = function
200202
201203
202204
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

pytest_flask/fixtures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ def _rewrite_server_name(server_name, new_port):
116116
return sep.join((server_name, new_port))
117117

118118

119-
def determine_scope(fixture_name, config):
120-
return config.getoption('--live-server-scope', 'session')
119+
def determine_scope(*, fixture_name, config):
120+
return config.getini('live_server_scope')
121121

122122

123123
@pytest.fixture(scope=determine_scope)

pytest_flask/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ def pytest_addoption(parser):
168168
help='use a host where to listen (default localhost).')
169169
group.addoption('--live-server-port', action='store', default=0, type=int,
170170
help='use a fixed port for the live_server fixture.')
171-
group.addoption('--live-server-scope', action='store', default='session', type=str,
172-
help='modify the scope of the live_server fixture.')
171+
parser.addini('live_server_scope', 'modify the scope of the live_server fixture.',
172+
default='session')
173173

174174

175175
def pytest_configure(config):

tests/test_live_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_a(live_server):
4242
'example.com:%d' % live_server.port
4343
''')
4444

45-
result = appdir.runpytest('-v', '--live-server-scope=function')
45+
result = appdir.runpytest('-v', '-o=live_server_scope=function')
4646
result.stdout.fnmatch_lines(['*PASSED*'])
4747
assert result.ret == 0
4848

0 commit comments

Comments
 (0)