Skip to content

Commit 486fa25

Browse files
authored
Merge branch 'master' into add_remote_hook
2 parents ad5e352 + bc44fea commit 486fa25

15 files changed

+283
-48
lines changed

CHANGELOG.rst

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,61 @@
1+
pytest-xdist 1.26.1 (2019-01-28)
2+
================================
3+
4+
Bug Fixes
5+
---------
6+
7+
- `#406 <https://github.com/pytest-dev/pytest-xdist/issues/406>`_: Do not implement deprecated ``pytest_logwarning`` hook in pytest versions where it is deprecated.
8+
9+
10+
pytest-xdist 1.26.0 (2019-01-11)
11+
================================
12+
13+
Features
14+
--------
15+
16+
- `#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.
17+
18+
This behavior is surprising because it makes xdist runs and non-xdist runs to potentially behave differently.
19+
20+
21+
Bug Fixes
22+
---------
23+
24+
- `#379 <https://github.com/pytest-dev/pytest-xdist/issues/379>`_: Warning attributes are checked to make sure they can be dumped prior to
25+
serializing the warning for submission to the master node.
26+
27+
28+
pytest-xdist 1.25.0 (2018-12-12)
29+
================================
30+
31+
Deprecations and Removals
32+
-------------------------
33+
34+
- `#372 <https://github.com/pytest-dev/pytest-xdist/issues/372>`_: Pytest versions older than 3.6 are no longer supported.
35+
36+
37+
Features
38+
--------
39+
40+
- `#373 <https://github.com/pytest-dev/pytest-xdist/issues/373>`_: Node setup information is hidden when pytest is run in quiet mode to reduce noise on many-core machines.
41+
42+
- `#388 <https://github.com/pytest-dev/pytest-xdist/issues/388>`_: ``mainargv`` is made available in ``workerinput`` from the host's ``sys.argv``.
43+
44+
This can be used via ``request.config.workerinput["mainargv"]``.
45+
46+
47+
Bug Fixes
48+
---------
49+
50+
- `#332 <https://github.com/pytest-dev/pytest-xdist/issues/332>`_: Fix report of module-level skips (``pytest.skip(reason, allow_module_level=True)``).
51+
52+
- `#378 <https://github.com/pytest-dev/pytest-xdist/issues/378>`_: Fix support for gevent monkeypatching
53+
54+
- `#384 <https://github.com/pytest-dev/pytest-xdist/issues/384>`_: pytest 4.1 support: ``ExceptionInfo`` API changes.
55+
56+
- `#390 <https://github.com/pytest-dev/pytest-xdist/issues/390>`_: pytest 4.1 support: ``pytest_logwarning`` hook removed.
57+
58+
159
pytest-xdist 1.24.1 (2018-11-09)
260
================================
361

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ defined:
223223
The information about the worker_id in a test is stored in the ``TestReport`` as
224224
well, under the ``worker_id`` attribute.
225225

226+
Acessing ``sys.argv`` from the master node in workers
227+
-----------------------------------------------------
228+
229+
To access the ``sys.argv`` passed to the command-line of the master node, use
230+
``request.config.workerinput["mainargv"]``.
231+
226232

227233
Specifying test exec environments in an ini file
228234
------------------------------------------------

changelog/332.bugfix.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

changelog/372.removal.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

changelog/415.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve behavior of ``--numprocesses=auto`` to work well with ``--pdb`` option.

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
install_requires = ["execnet>=1.1", "pytest>=3.6.0", "pytest-forked", "six"]
44

55

6+
with open("README.rst") as f:
7+
long_description = f.read()
8+
69
setup(
710
name="pytest-xdist",
811
use_scm_version={"write_to": "xdist/_version.py"},
912
description="pytest xdist plugin for distributed testing"
1013
" and loop-on-failing modes",
11-
long_description=open("README.rst").read(),
14+
long_description=long_description,
1215
license="MIT",
1316
author="holger krekel and contributors",
1417

testing/acceptance_test.py

Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import re
3+
import sys
34
import textwrap
45

56
import py
@@ -358,6 +359,30 @@ def test_hello():
358359

359360

360361
class TestTerminalReporting:
362+
@pytest.mark.parametrize("verbosity", ["", "-q", "-v"])
363+
def test_output_verbosity(self, testdir, verbosity):
364+
testdir.makepyfile(
365+
"""
366+
def test_ok():
367+
pass
368+
"""
369+
)
370+
args = ["-n1"]
371+
if verbosity:
372+
args.append(verbosity)
373+
result = testdir.runpytest(*args)
374+
out = result.stdout.str()
375+
if verbosity == "-v":
376+
assert "scheduling tests" in out
377+
assert "gw" in out
378+
elif verbosity == "-q":
379+
assert "scheduling tests" not in out
380+
assert "gw" not in out
381+
assert "bringing up nodes..." in out
382+
else:
383+
assert "scheduling tests" not in out
384+
assert "gw" in out
385+
361386
def test_pass_skip_fail(self, testdir):
362387
testdir.makepyfile(
363388
"""
@@ -465,9 +490,8 @@ def pytest_sessionfinish(session):
465490
name = "worker"
466491
else:
467492
name = "master"
468-
f = open(name, "w")
469-
f.write("xy")
470-
f.close()
493+
with open(name, "w") as f:
494+
f.write("xy")
471495
# let's fail on the worker
472496
if name == "worker":
473497
raise ValueError(42)
@@ -517,16 +541,15 @@ def pytest_sessionfinish(session):
517541
assert collected_file.read() == "collected = 3"
518542

519543

520-
def test_funcarg_teardown_failure(testdir):
544+
def test_fixture_teardown_failure(testdir):
521545
p = testdir.makepyfile(
522546
"""
523547
import pytest
524-
@pytest.fixture
548+
@pytest.fixture(scope="module")
525549
def myarg(request):
526-
def teardown(val):
527-
raise ValueError(val)
528-
return request.cached_setup(setup=lambda: 42, teardown=teardown,
529-
scope="module")
550+
yield 42
551+
raise ValueError(42)
552+
530553
def test_hello(myarg):
531554
pass
532555
"""
@@ -612,6 +635,11 @@ def test_crash():
612635

613636

614637
def test_issue34_pluginloading_in_subprocess(testdir):
638+
import _pytest.hookspec
639+
640+
if not hasattr(_pytest.hookspec, "pytest_namespace"):
641+
pytest.skip("this pytest version no longer supports pytest_namespace()")
642+
615643
testdir.tmpdir.join("plugin123.py").write(
616644
textwrap.dedent(
617645
"""
@@ -710,10 +738,12 @@ def test_ok():
710738
class TestWarnings:
711739
@pytest.mark.parametrize("n", ["-n0", "-n1"])
712740
@pytest.mark.parametrize("warn_type", ["pytest", "builtin"])
713-
def test_warnings(self, testdir, n, warn_type):
741+
def test_warnings(self, testdir, n, request, warn_type):
714742
if warn_type == "builtin":
715743
warn_code = """warnings.warn(UserWarning('this is a warning'))"""
716744
elif warn_type == "pytest":
745+
if not hasattr(request.config, "warn"):
746+
pytest.skip("config.warn has been removed in pytest 4.1")
717747
warn_code = """request.config.warn('', 'this is a warning',
718748
fslocation=py.path.local())"""
719749
else:
@@ -773,6 +803,39 @@ def test_func(tmpdir):
773803
result = testdir.runpytest(n)
774804
result.stdout.fnmatch_lines(["*UserWarning*foo.txt*", "*1 passed, 1 warnings*"])
775805

806+
@pytest.mark.parametrize("n", ["-n0", "-n1"])
807+
def test_unserializable_warning_details(self, testdir, n):
808+
"""Check that warnings with unserializable _WARNING_DETAILS are
809+
handled correctly (#379).
810+
"""
811+
if sys.version_info[0] < 3:
812+
# The issue is only present in Python 3 warnings
813+
return
814+
testdir.makepyfile(
815+
"""
816+
import warnings, pytest
817+
import socket
818+
import gc
819+
def abuse_socket():
820+
s = socket.socket()
821+
del s
822+
823+
# Deliberately provoke a ResourceWarning for an unclosed socket.
824+
# The socket itself will end up attached as a value in
825+
# _WARNING_DETAIL. We need to test that it is not serialized
826+
# (it can't be, so the test will fail if we try to).
827+
@pytest.mark.filterwarnings('always')
828+
def test_func(tmpdir):
829+
abuse_socket()
830+
gc.collect()
831+
"""
832+
)
833+
testdir.syspathinsert()
834+
result = testdir.runpytest(n)
835+
result.stdout.fnmatch_lines(
836+
["*ResourceWarning*unclosed*", "*1 passed, 1 warnings*"]
837+
)
838+
776839

777840
class TestNodeFailure:
778841
def test_load_single(self, testdir):

testing/test_plugin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def test_dist_options(testdir):
3636

3737
def test_auto_detect_cpus(testdir, monkeypatch):
3838
import os
39+
from xdist.plugin import pytest_cmdline_main as check_options
3940

4041
if hasattr(os, "sched_getaffinity"):
4142
monkeypatch.setattr(os, "sched_getaffinity", lambda _pid: set(range(99)))
@@ -52,6 +53,11 @@ def test_auto_detect_cpus(testdir, monkeypatch):
5253
config = testdir.parseconfigure("-nauto")
5354
assert config.getoption("numprocesses") == 99
5455

56+
config = testdir.parseconfigure("-nauto", "--pdb")
57+
check_options(config)
58+
assert config.getoption("usepdb")
59+
assert config.getoption("numprocesses") == 0
60+
5561
monkeypatch.delattr(os, "sched_getaffinity", raising=False)
5662
monkeypatch.setenv("TRAVIS", "true")
5763
config = testdir.parseconfigure("-nauto")

testing/test_remote.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import py
22
import pprint
33
import pytest
4+
import sys
45

56
from xdist.workermanage import WorkerController, unserialize_report
67
from xdist.remote import serialize_report
@@ -152,7 +153,6 @@ def test_repr_entry():
152153
for i in range(len(a_entries)):
153154
assert isinstance(rep_entries[i], ReprEntry)
154155
assert rep_entries[i].lines == a_entries[i].lines
155-
assert rep_entries[i].localssep == a_entries[i].localssep
156156
assert rep_entries[i].reprfileloc.lineno == a_entries[i].reprfileloc.lineno
157157
assert (
158158
rep_entries[i].reprfileloc.message == a_entries[i].reprfileloc.message
@@ -397,3 +397,64 @@ def test():
397397
)
398398
result = testdir.runpytest("-n2", "--max-worker-restart=0")
399399
assert result.ret == 0
400+
401+
402+
def test_remote_inner_argv(testdir):
403+
"""Test/document the behavior due to execnet using `python -c`."""
404+
testdir.makepyfile(
405+
"""
406+
import sys
407+
408+
def test_argv():
409+
assert sys.argv == ["-c"]
410+
"""
411+
)
412+
result = testdir.runpytest("-n1")
413+
assert result.ret == 0
414+
415+
416+
def test_remote_mainargv(testdir):
417+
outer_argv = sys.argv
418+
419+
testdir.makepyfile(
420+
"""
421+
def test_mainargv(request):
422+
assert request.config.workerinput["mainargv"] == {!r}
423+
""".format(
424+
outer_argv
425+
)
426+
)
427+
result = testdir.runpytest("-n1")
428+
assert result.ret == 0
429+
430+
431+
def test_remote_usage_prog(testdir, request):
432+
if not hasattr(request.config._parser, "prog"):
433+
pytest.skip("prog not available in config parser")
434+
testdir.makeconftest(
435+
"""
436+
import pytest
437+
438+
config_parser = None
439+
440+
@pytest.fixture
441+
def get_config_parser():
442+
return config_parser
443+
444+
def pytest_configure(config):
445+
global config_parser
446+
config_parser = config._parser
447+
"""
448+
)
449+
testdir.makepyfile(
450+
"""
451+
import sys
452+
453+
def test(get_config_parser, request):
454+
get_config_parser._getparser().error("my_usage_error")
455+
"""
456+
)
457+
458+
result = testdir.runpytest_subprocess("-n1")
459+
assert result.ret == 1
460+
result.stdout.fnmatch_lines(["*usage: *", "*error: my_usage_error"])

xdist/dsession.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,10 @@ def worker_collectionfinish(self, node, ids):
229229
if self.terminal and not self.sched.has_pending:
230230
self.trdist.ensure_show_status()
231231
self.terminal.write_line("")
232-
self.terminal.write_line(
233-
"scheduling tests via %s" % (self.sched.__class__.__name__)
234-
)
232+
if self.config.option.verbose > 0:
233+
self.terminal.write_line(
234+
"scheduling tests via %s" % (self.sched.__class__.__name__)
235+
)
235236
self.sched.schedule()
236237

237238
def worker_logstart(self, node, nodeid, location):
@@ -344,8 +345,11 @@ def setstatus(self, spec, status, show=True):
344345
self.rewrite(self.getstatus())
345346

346347
def getstatus(self):
347-
parts = ["%s %s" % (spec.id, self._status[spec.id]) for spec in self._specs]
348-
return " / ".join(parts)
348+
if self.config.option.verbose >= 0:
349+
parts = ["%s %s" % (spec.id, self._status[spec.id]) for spec in self._specs]
350+
return " / ".join(parts)
351+
else:
352+
return "bringing up nodes..."
349353

350354
def rewrite(self, line, newline=False):
351355
pline = line + " " * max(self._lastlen - len(line), 0)

0 commit comments

Comments
 (0)