Merge pull request #851 from nicoddemus/789-default-dist-mode
Let users configure dist mode in the configuration file
This commit is contained in:
6
changelog/789.feature.rst
Normal file
6
changelog/789.feature.rst
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Users can now set a default distribution mode in their configuration file:
|
||||||
|
|
||||||
|
.. code-block:: ini
|
||||||
|
|
||||||
|
[pytest]
|
||||||
|
addopts = --dist loadscope
|
||||||
@@ -190,7 +190,19 @@ def pytest_addhooks(pluginmanager):
|
|||||||
|
|
||||||
@pytest.hookimpl(trylast=True)
|
@pytest.hookimpl(trylast=True)
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
if config.getoption("dist") != "no" and not config.getvalue("collectonly"):
|
config_line = (
|
||||||
|
"xdist_group: specify group for tests should run in same session."
|
||||||
|
"in relation to one another. Provided by pytest-xdist."
|
||||||
|
)
|
||||||
|
config.addinivalue_line("markers", config_line)
|
||||||
|
|
||||||
|
# Skip this plugin entirely when only doing collection.
|
||||||
|
if config.getvalue("collectonly"):
|
||||||
|
return
|
||||||
|
|
||||||
|
# Create the distributed session in case we have a valid distribution
|
||||||
|
# mode and test environments.
|
||||||
|
if config.getoption("dist") != "no" and config.getoption("tx"):
|
||||||
from xdist.dsession import DSession
|
from xdist.dsession import DSession
|
||||||
|
|
||||||
session = DSession(config)
|
session = DSession(config)
|
||||||
@@ -199,6 +211,7 @@ def pytest_configure(config):
|
|||||||
if tr:
|
if tr:
|
||||||
tr.showfspath = False
|
tr.showfspath = False
|
||||||
|
|
||||||
|
# Deprecation warnings for deprecated command-line/configuration options.
|
||||||
if config.getoption("looponfail", None) or config.getini("looponfailroots"):
|
if config.getoption("looponfail", None) or config.getini("looponfailroots"):
|
||||||
warning = DeprecationWarning(
|
warning = DeprecationWarning(
|
||||||
"The --looponfail command line argument and looponfailroots config variable are deprecated.\n"
|
"The --looponfail command line argument and looponfailroots config variable are deprecated.\n"
|
||||||
@@ -213,12 +226,6 @@ def pytest_configure(config):
|
|||||||
)
|
)
|
||||||
config.issue_config_time_warning(warning, 2)
|
config.issue_config_time_warning(warning, 2)
|
||||||
|
|
||||||
config_line = (
|
|
||||||
"xdist_group: specify group for tests should run in same session."
|
|
||||||
"in relation to one another. " + "Provided by pytest-xdist."
|
|
||||||
)
|
|
||||||
config.addinivalue_line("markers", config_line)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.hookimpl(tryfirst=True)
|
@pytest.hookimpl(tryfirst=True)
|
||||||
def pytest_cmdline_main(config):
|
def pytest_cmdline_main(config):
|
||||||
|
|||||||
@@ -1561,3 +1561,21 @@ def test_collection_crash(testdir):
|
|||||||
"*= 1 error in *",
|
"*= 1 error in *",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dist_in_addopts(testdir):
|
||||||
|
"""Users can set a default distribution in the configuration file (#789)."""
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
def test():
|
||||||
|
pass
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
testdir.makeini(
|
||||||
|
"""
|
||||||
|
[pytest]
|
||||||
|
addopts = --dist loadscope
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
result = testdir.runpytest()
|
||||||
|
assert result.ret == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user