Skip to content

Commit 7a0bc4c

Browse files
committed
Let users configure dist mode in the configuration file
Fix #789
1 parent c6bcd20 commit 7a0bc4c

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

Diff for: changelog/789.feature.rst

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Users can now set a default distribution mode in their configuration file:
2+
3+
.. code-block:: ini
4+
5+
[pytest]
6+
addopts = --dist loadscope

Diff for: src/xdist/plugin.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,19 @@ def pytest_addhooks(pluginmanager):
190190

191191
@pytest.hookimpl(trylast=True)
192192
def pytest_configure(config):
193-
if config.getoption("dist") != "no" and not config.getvalue("collectonly"):
193+
config_line = (
194+
"xdist_group: specify group for tests should run in same session."
195+
"in relation to one another. Provided by pytest-xdist."
196+
)
197+
config.addinivalue_line("markers", config_line)
198+
199+
# Skip this plugin entirely when only doing collection.
200+
if config.getvalue("collectonly"):
201+
return
202+
203+
# Create the distributed session in case we have a valid distribution
204+
# mode and test environments.
205+
if config.getoption("dist") != "no" and config.getoption("tx"):
194206
from xdist.dsession import DSession
195207

196208
session = DSession(config)
@@ -199,6 +211,7 @@ def pytest_configure(config):
199211
if tr:
200212
tr.showfspath = False
201213

214+
# Deprecation warnings for deprecated command-line/configuration options.
202215
if config.getoption("looponfail", None) or config.getini("looponfailroots"):
203216
warning = DeprecationWarning(
204217
"The --looponfail command line argument and looponfailroots config variable are deprecated.\n"
@@ -213,12 +226,6 @@ def pytest_configure(config):
213226
)
214227
config.issue_config_time_warning(warning, 2)
215228

216-
config_line = (
217-
"xdist_group: specify group for tests should run in same session."
218-
"in relation to one another. " + "Provided by pytest-xdist."
219-
)
220-
config.addinivalue_line("markers", config_line)
221-
222229

223230
@pytest.hookimpl(tryfirst=True)
224231
def pytest_cmdline_main(config):

Diff for: testing/acceptance_test.py

+18
Original file line numberDiff line numberDiff line change
@@ -1561,3 +1561,21 @@ def test_collection_crash(testdir):
15611561
"*= 1 error in *",
15621562
]
15631563
)
1564+
1565+
1566+
def test_dist_in_addopts(testdir):
1567+
"""Users can set a default distribution in the configuration file (#789)."""
1568+
testdir.makepyfile(
1569+
"""
1570+
def test():
1571+
pass
1572+
"""
1573+
)
1574+
testdir.makeini(
1575+
"""
1576+
[pytest]
1577+
addopts = --dist loadscope
1578+
"""
1579+
)
1580+
result = testdir.runpytest()
1581+
assert result.ret == 0

0 commit comments

Comments
 (0)