Compare commits

..

41 Commits

Author SHA1 Message Date
Bruno Oliveira
d9c43a0933 Release 1.27.0 2019-02-15 12:17:48 -02:00
Bruno Oliveira
d753e53ee4 Merge pull request #374 from illiterati1/add_remote_hook
Add a hook to allow overriding the remote module that's executed by e…
2019-02-15 12:17:01 -02:00
Bruno Oliveira
81309e8d69 Adust linting and CHANGELOG 2019-02-15 09:35:06 -02:00
Bruno Oliveira
26d0fcabf6 Fix linting 2019-02-15 09:31:14 -02:00
Bruno Oliveira
486fa25bcb Merge branch 'master' into add_remote_hook 2019-02-15 09:23:32 -02:00
Bruno Oliveira
bc44fea8a8 Merge pull request #415 from jirikuncar/numprocesses-auto-with-pdb
Improve behavior of --numprocesses=auto and --pdb
2019-02-15 09:20:51 -02:00
Bruno Oliveira
6d544cef9a Fix linting 2019-02-15 08:37:57 -02:00
Jiri Kuncar
93780dcccc Simpler usage error in test_remote_usage_prog 2019-02-15 10:54:18 +01:00
Bruno Oliveira
ca58e5e7ed Fix test_remote_usage_prog after changes in pytest features branch 2019-02-13 15:20:32 -02:00
Jiri Kuncar
d8a794bc84 Improve behavior of -n=auto with --pdb option 2019-02-12 15:57:55 +01:00
Bruno Oliveira
ca032692a8 Merge pull request #407 from nicoddemus/pytest-logwarning-deprecation
Handle pytest_logwarning deprecation better and prepare next release
2019-01-28 18:52:09 -02:00
Bruno Oliveira
6fc02bb04a Release 1.26.1 2019-01-28 18:07:36 -02:00
Bruno Oliveira
c5f65b39ec Do not implement pytest_logwarning in pytest versions where it is deprecated
Fix #406
2019-01-28 18:05:41 -02:00
Bruno Oliveira
f00f9ecf58 Merge pull request #403 from BoboTiG/fix-resource-leaks
Fix ResourceWarning: unclosed file in setup.py
2019-01-15 08:22:08 -02:00
Ronny Pfannschmidt
48b7014530 Merge pull request #401 from nicoddemus/mainargv-docs
Add docs for sys.argv access from workers
2019-01-15 06:16:41 +01:00
Bruno Oliveira
1dec9dc246 ReprEntry objects no longer have the localssep attribute
The attribute was not used anywhere and has been removed in
pytest-dev/pytest#4615
2019-01-14 21:59:05 -02:00
Mickaël Schoentgen
f6ecaa9b7f Fix ResourceWarning: unclosed file in setup.py
Also uniformize the usage of the 'with' context manager.

Signed-off-by: Mickaël Schoentgen <contact@tiger-222.fr>
2019-01-14 22:59:36 +01:00
Bruno Oliveira
1276df4cfa Add docs for sys.argv access from workers 2019-01-11 21:59:33 -02:00
Bruno Oliveira
ccdb36a477 Merge pull request #400 from nicoddemus/release-1.26.0
Release 1.26.0
2019-01-11 21:14:46 -02:00
Bruno Oliveira
45ddc221ef Release 1.26.0 2019-01-11 15:19:37 -02:00
Bruno Oliveira
c3dbd05bd1 Merge pull request #379 from aadamson/warning-details-dumps-check
Check that we can serialize the warning detail attr
2019-01-11 15:17:02 -02:00
Bruno Oliveira
b9423d894c Fix linting 2019-01-10 19:19:34 -02:00
Alex Adamson
242c009866 Remove trailing whitespace 2019-01-10 15:50:25 -05:00
Alex Adamson
0ee219dc48 Address comments 2019-01-10 15:45:48 -05:00
bwilson
ad5e35213d moving py import 2019-01-09 16:17:57 -06:00
Bruno Oliveira
76075f5de1 Merge pull request #397 from nicoddemus/do-not-change-pythonpath
Do not change PYTHONPATH or sys.path on workers
2019-01-09 18:40:02 -02:00
Bruno Oliveira
f8d51aab57 Do not change PYTHONPATH or sys.path on local workers
Fix #376
2019-01-09 11:14:35 -02:00
Alex Adamson
ac2bf10fe2 Disable unserialized arguments check for py2 2019-01-08 15:17:03 -05:00
Alex Adamson
fa85371c73 Add test for #379 2019-01-08 15:17:03 -05:00
Alex Adamson
d55fab3aa7 Add changelog entry 2019-01-08 15:17:03 -05:00
Alex Adamson
4632df37a6 Check that we can serialize the warning detail attr 2019-01-08 15:17:03 -05:00
Bruno Oliveira
ca94bda1b7 Merge pull request #396 from nicoddemus/fix-4.1.0-tests
Skip config.warn tests in pytest 4.1
2019-01-08 17:18:13 -02:00
Bruno Oliveira
261d4189f0 Skip config.warn tests in pytest 4.1 2019-01-08 10:57:14 -02:00
Bruno Oliveira
f283dddf36 Merge pull request #392 from nicoddemus/release-1.25.0
Release 1.25.0
2018-12-13 11:09:27 -02:00
bwilson
ab5f12f92e Revert "Adding RemoteTarget class to wrap module/function"
This reverts commit 311554324a.
2018-11-26 09:49:11 -06:00
bwilson
b28c3d98c5 Revert "linting"
This reverts commit b94dcfe4cd.
2018-11-26 09:49:10 -06:00
bwilson
b94dcfe4cd linting 2018-11-13 10:45:40 -06:00
bwilson
311554324a Adding RemoteTarget class to wrap module/function 2018-11-13 10:37:37 -06:00
bwilson
5bb35b0f26 fixing linting problem with changelog 2018-11-12 13:53:35 -06:00
bwilson
47d271ad97 Adding news file 2018-11-12 13:41:18 -06:00
bwilson
7fb7bd9d04 Add a hook to allow overriding the remote module that's executed by execnet 2018-11-12 13:29:39 -06:00
10 changed files with 147 additions and 27 deletions

View File

@@ -1,3 +1,41 @@
pytest-xdist 1.27.0 (2019-02-15)
================================
Features
--------
- `#374 <https://github.com/pytest-dev/pytest-xdist/issues/374>`_: The new ``pytest_xdist_getremotemodule`` hook allows overriding the module run on remote nodes.
- `#415 <https://github.com/pytest-dev/pytest-xdist/issues/415>`_: Improve behavior of ``--numprocesses=auto`` to work well with ``--pdb`` option.
pytest-xdist 1.26.1 (2019-01-28)
================================
Bug Fixes
---------
- `#406 <https://github.com/pytest-dev/pytest-xdist/issues/406>`_: Do not implement deprecated ``pytest_logwarning`` hook in pytest versions where it is deprecated.
pytest-xdist 1.26.0 (2019-01-11)
================================
Features
--------
- `#376 <https://github.com/pytest-dev/pytest-xdist/issues/376>`_: The current directory is no longer added ``sys.path`` for local workers, only for remote connections.
This behavior is surprising because it makes xdist runs and non-xdist runs to potentially behave differently.
Bug Fixes
---------
- `#379 <https://github.com/pytest-dev/pytest-xdist/issues/379>`_: Warning attributes are checked to make sure they can be dumped prior to
serializing the warning for submission to the master node.
pytest-xdist 1.25.0 (2018-12-12) pytest-xdist 1.25.0 (2018-12-12)
================================ ================================

View File

@@ -223,6 +223,12 @@ defined:
The information about the worker_id in a test is stored in the ``TestReport`` as The information about the worker_id in a test is stored in the ``TestReport`` as
well, under the ``worker_id`` attribute. well, under the ``worker_id`` attribute.
Acessing ``sys.argv`` from the master node in workers
-----------------------------------------------------
To access the ``sys.argv`` passed to the command-line of the master node, use
``request.config.workerinput["mainargv"]``.
Specifying test exec environments in an ini file Specifying test exec environments in an ini file
------------------------------------------------ ------------------------------------------------

View File

@@ -3,12 +3,15 @@ from setuptools import setup, find_packages
install_requires = ["execnet>=1.1", "pytest>=3.6.0", "pytest-forked", "six"] install_requires = ["execnet>=1.1", "pytest>=3.6.0", "pytest-forked", "six"]
with open("README.rst") as f:
long_description = f.read()
setup( setup(
name="pytest-xdist", name="pytest-xdist",
use_scm_version={"write_to": "xdist/_version.py"}, use_scm_version={"write_to": "xdist/_version.py"},
description="pytest xdist plugin for distributed testing" description="pytest xdist plugin for distributed testing"
" and loop-on-failing modes", " and loop-on-failing modes",
long_description=open("README.rst").read(), long_description=long_description,
license="MIT", license="MIT",
author="holger krekel and contributors", author="holger krekel and contributors",
author_email="pytest-dev@python.org,holger@merlinux.eu", author_email="pytest-dev@python.org,holger@merlinux.eu",

View File

@@ -1,5 +1,6 @@
import os import os
import re import re
import sys
import textwrap import textwrap
import py import py
@@ -489,9 +490,8 @@ def test_session_hooks(testdir):
name = "worker" name = "worker"
else: else:
name = "master" name = "master"
f = open(name, "w") with open(name, "w") as f:
f.write("xy") f.write("xy")
f.close()
# let's fail on the worker # let's fail on the worker
if name == "worker": if name == "worker":
raise ValueError(42) raise ValueError(42)
@@ -738,10 +738,12 @@ def test_sub_plugins_disabled(testdir, plugin):
class TestWarnings: class TestWarnings:
@pytest.mark.parametrize("n", ["-n0", "-n1"]) @pytest.mark.parametrize("n", ["-n0", "-n1"])
@pytest.mark.parametrize("warn_type", ["pytest", "builtin"]) @pytest.mark.parametrize("warn_type", ["pytest", "builtin"])
def test_warnings(self, testdir, n, warn_type): def test_warnings(self, testdir, n, request, warn_type):
if warn_type == "builtin": if warn_type == "builtin":
warn_code = """warnings.warn(UserWarning('this is a warning'))""" warn_code = """warnings.warn(UserWarning('this is a warning'))"""
elif warn_type == "pytest": elif warn_type == "pytest":
if not hasattr(request.config, "warn"):
pytest.skip("config.warn has been removed in pytest 4.1")
warn_code = """request.config.warn('', 'this is a warning', warn_code = """request.config.warn('', 'this is a warning',
fslocation=py.path.local())""" fslocation=py.path.local())"""
else: else:
@@ -801,6 +803,39 @@ class TestWarnings:
result = testdir.runpytest(n) result = testdir.runpytest(n)
result.stdout.fnmatch_lines(["*UserWarning*foo.txt*", "*1 passed, 1 warnings*"]) result.stdout.fnmatch_lines(["*UserWarning*foo.txt*", "*1 passed, 1 warnings*"])
@pytest.mark.parametrize("n", ["-n0", "-n1"])
def test_unserializable_warning_details(self, testdir, n):
"""Check that warnings with unserializable _WARNING_DETAILS are
handled correctly (#379).
"""
if sys.version_info[0] < 3:
# The issue is only present in Python 3 warnings
return
testdir.makepyfile(
"""
import warnings, pytest
import socket
import gc
def abuse_socket():
s = socket.socket()
del s
# Deliberately provoke a ResourceWarning for an unclosed socket.
# The socket itself will end up attached as a value in
# _WARNING_DETAIL. We need to test that it is not serialized
# (it can't be, so the test will fail if we try to).
@pytest.mark.filterwarnings('always')
def test_func(tmpdir):
abuse_socket()
gc.collect()
"""
)
testdir.syspathinsert()
result = testdir.runpytest(n)
result.stdout.fnmatch_lines(
["*ResourceWarning*unclosed*", "*1 passed, 1 warnings*"]
)
class TestNodeFailure: class TestNodeFailure:
def test_load_single(self, testdir): def test_load_single(self, testdir):

View File

@@ -36,6 +36,7 @@ def test_dist_options(testdir):
def test_auto_detect_cpus(testdir, monkeypatch): def test_auto_detect_cpus(testdir, monkeypatch):
import os import os
from xdist.plugin import pytest_cmdline_main as check_options
if hasattr(os, "sched_getaffinity"): if hasattr(os, "sched_getaffinity"):
monkeypatch.setattr(os, "sched_getaffinity", lambda _pid: set(range(99))) monkeypatch.setattr(os, "sched_getaffinity", lambda _pid: set(range(99)))
@@ -52,6 +53,11 @@ def test_auto_detect_cpus(testdir, monkeypatch):
config = testdir.parseconfigure("-nauto") config = testdir.parseconfigure("-nauto")
assert config.getoption("numprocesses") == 99 assert config.getoption("numprocesses") == 99
config = testdir.parseconfigure("-nauto", "--pdb")
check_options(config)
assert config.getoption("usepdb")
assert config.getoption("numprocesses") == 0
monkeypatch.delattr(os, "sched_getaffinity", raising=False) monkeypatch.delattr(os, "sched_getaffinity", raising=False)
monkeypatch.setenv("TRAVIS", "true") monkeypatch.setenv("TRAVIS", "true")
config = testdir.parseconfigure("-nauto") config = testdir.parseconfigure("-nauto")

View File

@@ -153,7 +153,6 @@ class TestReportSerialization:
for i in range(len(a_entries)): for i in range(len(a_entries)):
assert isinstance(rep_entries[i], ReprEntry) assert isinstance(rep_entries[i], ReprEntry)
assert rep_entries[i].lines == a_entries[i].lines assert rep_entries[i].lines == a_entries[i].lines
assert rep_entries[i].localssep == a_entries[i].localssep
assert rep_entries[i].reprfileloc.lineno == a_entries[i].reprfileloc.lineno assert rep_entries[i].reprfileloc.lineno == a_entries[i].reprfileloc.lineno
assert ( assert (
rep_entries[i].reprfileloc.message == a_entries[i].reprfileloc.message rep_entries[i].reprfileloc.message == a_entries[i].reprfileloc.message
@@ -458,6 +457,4 @@ def test_remote_usage_prog(testdir, request):
result = testdir.runpytest_subprocess("-n1") result = testdir.runpytest_subprocess("-n1")
assert result.ret == 1 assert result.ret == 1
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(["*usage: *", "*error: my_usage_error"])
["usage: pytest.py *", "pytest.py: error: my_usage_error"]
)

View File

@@ -30,6 +30,11 @@ def pytest_xdist_rsyncfinish(source, gateways):
""" called after rsyncing a directory to remote gateways takes place. """ """ called after rsyncing a directory to remote gateways takes place. """
@pytest.mark.firstresult
def pytest_xdist_getremotemodule():
""" called when creating remote node"""
def pytest_configure_node(node): def pytest_configure_node(node):
""" configure node information before it gets instantiated. """ """ configure node information before it gets instantiated. """

View File

@@ -27,10 +27,14 @@ def auto_detect_cpus():
return n if n else 1 return n if n else 1
class AutoInt(int):
"""Mark value as auto-detected."""
def parse_numprocesses(s): def parse_numprocesses(s):
if s == "auto": if s == "auto":
return auto_detect_cpus() return AutoInt(auto_detect_cpus())
else: elif s is not None:
return int(s) return int(s)
@@ -45,7 +49,7 @@ def pytest_addoption(parser):
type=parse_numprocesses, type=parse_numprocesses,
help="shortcut for '--dist=load --tx=NUM*popen', " help="shortcut for '--dist=load --tx=NUM*popen', "
"you can use 'auto' here for auto detection CPUs number on " "you can use 'auto' here for auto detection CPUs number on "
"host system", "host system and it will be 0 when used with --pdb",
) )
group.addoption( group.addoption(
"--maxprocesses", "--maxprocesses",
@@ -177,6 +181,10 @@ def pytest_configure(config):
@pytest.mark.tryfirst @pytest.mark.tryfirst
def pytest_cmdline_main(config): def pytest_cmdline_main(config):
usepdb = config.getoption("usepdb") # a core option
if isinstance(config.option.numprocesses, AutoInt):
config.option.numprocesses = 0 if usepdb else int(config.option.numprocesses)
if config.option.numprocesses: if config.option.numprocesses:
if config.option.dist == "no": if config.option.dist == "no":
config.option.dist = "load" config.option.dist = "load"
@@ -188,11 +196,10 @@ def pytest_cmdline_main(config):
config.option.dist = "load" config.option.dist = "load"
val = config.getvalue val = config.getvalue
if not val("collectonly"): if not val("collectonly"):
usepdb = config.getoption("usepdb") # a core option
if val("dist") != "no": if val("dist") != "no":
if usepdb: if usepdb:
raise pytest.UsageError( raise pytest.UsageError(
"--pdb is incompatible with distributing tests; try using -n0." "--pdb is incompatible with distributing tests; try using -n0 or -nauto."
) # noqa: E501 ) # noqa: E501

View File

@@ -10,6 +10,7 @@ import sys
import os import os
import time import time
import py
import _pytest.hookspec import _pytest.hookspec
import pytest import pytest
from execnet.gateway_base import dumps, DumpError from execnet.gateway_base import dumps, DumpError
@@ -115,8 +116,10 @@ class WorkerInteractor(object):
data = serialize_report(report) data = serialize_report(report)
self.sendevent("collectreport", data=data) self.sendevent("collectreport", data=data)
# the pytest_logwarning hook was removed in pytest 4.1 # the pytest_logwarning hook was deprecated since pytest 4.0
if hasattr(_pytest.hookspec, "pytest_logwarning"): if hasattr(
_pytest.hookspec, "pytest_logwarning"
) and not _pytest.hookspec.pytest_logwarning.pytest_spec.get("warn_on_impl"):
def pytest_logwarning(self, message, code, nodeid, fslocation): def pytest_logwarning(self, message, code, nodeid, fslocation):
self.sendevent( self.sendevent(
@@ -218,7 +221,15 @@ def serialize_warning_message(warning_message):
for attr_name in warning_message._WARNING_DETAILS: for attr_name in warning_message._WARNING_DETAILS:
if attr_name in ("message", "category"): if attr_name in ("message", "category"):
continue continue
result[attr_name] = getattr(warning_message, attr_name) attr = getattr(warning_message, attr_name)
# Check if we can serialize the warning detail, marking `None` otherwise
# Note that we need to define the attr (even as `None`) to allow deserializing
try:
dumps(attr)
except DumpError:
result[attr_name] = repr(attr)
else:
result[attr_name] = attr
return result return result
@@ -252,16 +263,17 @@ def remote_initconfig(option_dict, args):
if __name__ == "__channelexec__": if __name__ == "__channelexec__":
channel = channel # noqa channel = channel # noqa
workerinput, args, option_dict = channel.receive() workerinput, args, option_dict, change_sys_path = channel.receive()
importpath = os.getcwd()
sys.path.insert(0, importpath) # XXX only for remote situations if change_sys_path:
os.environ["PYTHONPATH"] = ( importpath = os.getcwd()
importpath + os.pathsep + os.environ.get("PYTHONPATH", "") sys.path.insert(0, importpath)
) os.environ["PYTHONPATH"] = (
importpath + os.pathsep + os.environ.get("PYTHONPATH", "")
)
os.environ["PYTEST_XDIST_WORKER"] = workerinput["workerid"] os.environ["PYTEST_XDIST_WORKER"] = workerinput["workerid"]
os.environ["PYTEST_XDIST_WORKER_COUNT"] = str(workerinput["workercount"]) os.environ["PYTEST_XDIST_WORKER_COUNT"] = str(workerinput["workercount"])
# os.environ['PYTHONPATH'] = importpath
import py
config = remote_initconfig(option_dict, args) config = remote_initconfig(option_dict, args)
config._parser.prog = os.path.basename(workerinput["mainargv"][0]) config._parser.prog = os.path.basename(workerinput["mainargv"][0])

View File

@@ -204,7 +204,13 @@ def make_reltoroot(roots, args):
class WorkerController(object): class WorkerController(object):
ENDMARK = -1 ENDMARK = -1
class RemoteHook:
@pytest.mark.trylast
def pytest_xdist_getremotemodule(self):
return xdist.remote
def __init__(self, nodemanager, gateway, config, putevent): def __init__(self, nodemanager, gateway, config, putevent):
config.pluginmanager.register(self.RemoteHook())
self.nodemanager = nodemanager self.nodemanager = nodemanager
self.putevent = putevent self.putevent = putevent
self.gateway = gateway self.gateway = gateway
@@ -244,8 +250,13 @@ class WorkerController(object):
basetemp = self.config._tmpdirhandler.getbasetemp() basetemp = self.config._tmpdirhandler.getbasetemp()
option_dict["basetemp"] = str(basetemp.join(name)) option_dict["basetemp"] = str(basetemp.join(name))
self.config.hook.pytest_configure_node(node=self) self.config.hook.pytest_configure_node(node=self)
self.channel = self.gateway.remote_exec(xdist.remote)
self.channel.send((self.workerinput, args, option_dict)) remote_module = self.config.hook.pytest_xdist_getremotemodule()
self.channel = self.gateway.remote_exec(remote_module)
# change sys.path only for remote workers
change_sys_path = not self.gateway.spec.popen
self.channel.send((self.workerinput, args, option_dict, change_sys_path))
if self.putevent: if self.putevent:
self.channel.setcallback(self.process_from_remote, endmarker=self.ENDMARK) self.channel.setcallback(self.process_from_remote, endmarker=self.ENDMARK)