Compare commits
97 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa8037d365 | ||
|
|
13efbfba69 | ||
|
|
0b840f8726 | ||
|
|
0242acfa0a | ||
|
|
04c0265b6b | ||
|
|
7ab9cf1a7a | ||
|
|
875aed976e | ||
|
|
386c8eb416 | ||
|
|
fc8e1133ac | ||
|
|
89d07a5cf2 | ||
|
|
911dfdbcb6 | ||
|
|
ba434848f5 | ||
|
|
8960ee45c6 | ||
|
|
9f6754f64a | ||
|
|
2bcbdb6745 | ||
|
|
d9c43a0933 | ||
|
|
d753e53ee4 | ||
|
|
81309e8d69 | ||
|
|
26d0fcabf6 | ||
|
|
486fa25bcb | ||
|
|
bc44fea8a8 | ||
|
|
6d544cef9a | ||
|
|
93780dcccc | ||
|
|
ca58e5e7ed | ||
|
|
d8a794bc84 | ||
|
|
ca032692a8 | ||
|
|
6fc02bb04a | ||
|
|
c5f65b39ec | ||
|
|
f00f9ecf58 | ||
|
|
48b7014530 | ||
|
|
1dec9dc246 | ||
|
|
f6ecaa9b7f | ||
|
|
1276df4cfa | ||
|
|
ccdb36a477 | ||
|
|
45ddc221ef | ||
|
|
c3dbd05bd1 | ||
|
|
b9423d894c | ||
|
|
242c009866 | ||
|
|
0ee219dc48 | ||
|
|
ad5e35213d | ||
|
|
76075f5de1 | ||
|
|
f8d51aab57 | ||
|
|
ac2bf10fe2 | ||
|
|
fa85371c73 | ||
|
|
d55fab3aa7 | ||
|
|
4632df37a6 | ||
|
|
ca94bda1b7 | ||
|
|
261d4189f0 | ||
|
|
f283dddf36 | ||
|
|
6d74bab518 | ||
|
|
c306287a4e | ||
|
|
2b65800738 | ||
|
|
86bf3cb8b3 | ||
|
|
95aaaec6c5 | ||
|
|
33d5441258 | ||
|
|
b5c09f8e84 | ||
|
|
a30124e858 | ||
|
|
c5d8635294 | ||
|
|
5f0abe3cb8 | ||
|
|
3332c99e1e | ||
|
|
3329bbbae2 | ||
|
|
dd63d0b667 | ||
|
|
dd6eac12a4 | ||
|
|
a70dace69c | ||
|
|
6a21a5aa81 | ||
|
|
49c09117ed | ||
|
|
566480fdd3 | ||
|
|
ab5f12f92e | ||
|
|
b28c3d98c5 | ||
|
|
5ecbf25450 | ||
|
|
646eb868ab | ||
|
|
50b27d2735 | ||
|
|
16db6eddd7 | ||
|
|
f2061875e1 | ||
|
|
c4b365b082 | ||
|
|
b94dcfe4cd | ||
|
|
311554324a | ||
|
|
5465d936f7 | ||
|
|
b819657dac | ||
|
|
d8c6c22989 | ||
|
|
5bb35b0f26 | ||
|
|
47d271ad97 | ||
|
|
7fb7bd9d04 | ||
|
|
1efec5a153 | ||
|
|
f9a13fe53b | ||
|
|
74a5e0ca03 | ||
|
|
3292e0ede0 | ||
|
|
d40d47acd9 | ||
|
|
3579bfce7d | ||
|
|
365499eeaf | ||
|
|
a518bd4e2a | ||
|
|
d84ae73775 | ||
|
|
673fe9bd67 | ||
|
|
9217b80fb1 | ||
|
|
b151e56fbd | ||
|
|
70688b7986 | ||
|
|
adc385253c |
49
.travis.yml
49
.travis.yml
@@ -1,46 +1,47 @@
|
|||||||
sudo: false
|
dist: xenial
|
||||||
language: python
|
language: python
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
irc:
|
irc:
|
||||||
channels:
|
channels:
|
||||||
- 'chat.freenode.net#pytest'
|
- 'chat.freenode.net#pytest'
|
||||||
on_success: change
|
on_success: change
|
||||||
on_failure: change
|
on_failure: change
|
||||||
skip_join: true
|
skip_join: true
|
||||||
email:
|
email:
|
||||||
- pytest-commit@python.org
|
- pytest-commit@python.org
|
||||||
|
|
||||||
python:
|
install:
|
||||||
- '2.7'
|
- pip install -U pip
|
||||||
- '3.4'
|
- pip install tox setuptools_scm
|
||||||
- '3.5'
|
|
||||||
- '3.6'
|
|
||||||
env:
|
|
||||||
- TOXENV=py-pytest30
|
|
||||||
- TOXENV=py-pytest31
|
|
||||||
- TOXENV=py-pytest32
|
|
||||||
- TOXENV=py-pytest33
|
|
||||||
- TOXENV=py-pytest36
|
|
||||||
- TOXENV=py-pytest38
|
|
||||||
|
|
||||||
install: pip install tox setuptools_scm
|
|
||||||
script: tox
|
script: tox
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- linting
|
- baseline
|
||||||
- test
|
- test
|
||||||
- name: deploy
|
- name: deploy
|
||||||
if: repo = pytest-dev/pytest-xdist AND tag IS present
|
if: repo = pytest-dev/pytest-xdist AND tag IS present
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
include:
|
include:
|
||||||
- stage: linting
|
- stage: baseline
|
||||||
python: '3.6'
|
python: '3.6'
|
||||||
script:
|
env: TOXENV=linting
|
||||||
- tox -e linting
|
cache:
|
||||||
|
directories:
|
||||||
|
- $HOME/.cache/pre-commit
|
||||||
|
- python: '3.6'
|
||||||
|
env: TOXENV=py36-pytestlatest
|
||||||
|
- python: '2.7'
|
||||||
|
env: TOXENV=py27-pytestlatest
|
||||||
|
|
||||||
- stage: test
|
- stage: test
|
||||||
# python x env above are already included into this stage
|
python: "3.4"
|
||||||
|
env: TOXENV=py34-pytestlatest
|
||||||
|
- python: "3.5"
|
||||||
|
env: TOXENV=py35-pytestlatest
|
||||||
|
- python: "3.7"
|
||||||
|
env: TOXENV=py37-pytestlatest
|
||||||
- python: "2.7"
|
- python: "2.7"
|
||||||
env: TOXENV=py27-pytestmaster
|
env: TOXENV=py27-pytestmaster
|
||||||
- python: "2.7"
|
- python: "2.7"
|
||||||
|
|||||||
@@ -1,3 +1,94 @@
|
|||||||
|
pytest-xdist 1.28.0 (2019-04-02)
|
||||||
|
================================
|
||||||
|
|
||||||
|
Features
|
||||||
|
--------
|
||||||
|
|
||||||
|
- `#426 <https://github.com/pytest-dev/pytest-xdist/issues/426>`_: ``pytest-xdist`` now uses the new ``pytest_report_to_serializable`` and ``pytest_report_from_serializable``
|
||||||
|
hooks from ``pytest 4.4`` (still experimental). This will make report serialization more reliable and
|
||||||
|
extensible.
|
||||||
|
|
||||||
|
This also means that ``pytest-xdist`` now requires ``pytest>=4.4``.
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
================================
|
||||||
|
|
||||||
|
Deprecations and Removals
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
- `#372 <https://github.com/pytest-dev/pytest-xdist/issues/372>`_: Pytest versions older than 3.6 are no longer supported.
|
||||||
|
|
||||||
|
|
||||||
|
Features
|
||||||
|
--------
|
||||||
|
|
||||||
|
- `#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.
|
||||||
|
|
||||||
|
- `#388 <https://github.com/pytest-dev/pytest-xdist/issues/388>`_: ``mainargv`` is made available in ``workerinput`` from the host's ``sys.argv``.
|
||||||
|
|
||||||
|
This can be used via ``request.config.workerinput["mainargv"]``.
|
||||||
|
|
||||||
|
|
||||||
|
Bug Fixes
|
||||||
|
---------
|
||||||
|
|
||||||
|
- `#332 <https://github.com/pytest-dev/pytest-xdist/issues/332>`_: Fix report of module-level skips (``pytest.skip(reason, allow_module_level=True)``).
|
||||||
|
|
||||||
|
- `#378 <https://github.com/pytest-dev/pytest-xdist/issues/378>`_: Fix support for gevent monkeypatching
|
||||||
|
|
||||||
|
- `#384 <https://github.com/pytest-dev/pytest-xdist/issues/384>`_: pytest 4.1 support: ``ExceptionInfo`` API changes.
|
||||||
|
|
||||||
|
- `#390 <https://github.com/pytest-dev/pytest-xdist/issues/390>`_: pytest 4.1 support: ``pytest_logwarning`` hook removed.
|
||||||
|
|
||||||
|
|
||||||
|
pytest-xdist 1.24.1 (2018-11-09)
|
||||||
|
================================
|
||||||
|
|
||||||
|
Bug Fixes
|
||||||
|
---------
|
||||||
|
|
||||||
|
- `#349 <https://github.com/pytest-dev/pytest-xdist/issues/349>`_: Correctly handle warnings created with arguments that can't be serialized during the transfer from workers to master node.
|
||||||
|
|
||||||
|
|
||||||
pytest-xdist 1.24.0 (2018-10-18)
|
pytest-xdist 1.24.0 (2018-10-18)
|
||||||
================================
|
================================
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
------------------------------------------------
|
------------------------------------------------
|
||||||
|
|||||||
23
appveyor.yml
23
appveyor.yml
@@ -1,22 +1,23 @@
|
|||||||
environment:
|
environment:
|
||||||
matrix:
|
matrix:
|
||||||
# note: please use "tox --listenvs" to populate the build matrix
|
- TOXENV: "py27-pytestlatest"
|
||||||
- TOXENV: "py27-pytest33"
|
- TOXENV: "py34-pytestlatest"
|
||||||
- TOXENV: "py34-pytest33"
|
- TOXENV: "py35-pytestlatest"
|
||||||
- TOXENV: "py35-pytest33"
|
- TOXENV: "py36-pytestlatest"
|
||||||
- TOXENV: "py36-pytest33"
|
- TOXENV: "py37-pytestlatest"
|
||||||
- TOXENV: "py36-pytest36"
|
- TOXENV: "py27-pytestmaster"
|
||||||
- TOXENV: "py36-pytest38"
|
- TOXENV: "py36-pytestmaster"
|
||||||
- TOXENV: "py27-pytest33-pexpect"
|
- TOXENV: "py27-pytestfeatures"
|
||||||
- TOXENV: "py36-pytest33-pexpect"
|
- TOXENV: "py36-pytestfeatures"
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- C:\Python36\python -m pip install -U tox setuptools_scm pip
|
- C:\Python37\python -m pip install -U pip
|
||||||
|
- C:\Python37\python -m pip install -U tox setuptools_scm
|
||||||
|
|
||||||
build: false # Not a C# project, build stuff at the test step instead.
|
build: false # Not a C# project, build stuff at the test step instead.
|
||||||
|
|
||||||
test_script:
|
test_script:
|
||||||
- C:\Python36\python -m tox
|
- C:\Python37\python -m tox
|
||||||
|
|
||||||
# We don't deploy anything on tags with AppVeyor, we use Travis instead, so we
|
# We don't deploy anything on tags with AppVeyor, we use Travis instead, so we
|
||||||
# might as well save resources
|
# might as well save resources
|
||||||
|
|||||||
8
setup.py
8
setup.py
@@ -1,14 +1,17 @@
|
|||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
install_requires = ["execnet>=1.1", "pytest>=3.0.0", "pytest-forked", "six"]
|
install_requires = ["execnet>=1.1", "pytest>=4.4.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",
|
||||||
@@ -40,5 +43,6 @@ setup(
|
|||||||
"Programming Language :: Python :: 3.4",
|
"Programming Language :: Python :: 3.4",
|
||||||
"Programming Language :: Python :: 3.5",
|
"Programming Language :: Python :: 3.5",
|
||||||
"Programming Language :: Python :: 3.6",
|
"Programming Language :: Python :: 3.6",
|
||||||
|
"Programming Language :: Python :: 3.7",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
import py
|
import py
|
||||||
@@ -358,6 +359,30 @@ class TestDistEach:
|
|||||||
|
|
||||||
|
|
||||||
class TestTerminalReporting:
|
class TestTerminalReporting:
|
||||||
|
@pytest.mark.parametrize("verbosity", ["", "-q", "-v"])
|
||||||
|
def test_output_verbosity(self, testdir, verbosity):
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
def test_ok():
|
||||||
|
pass
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
args = ["-n1"]
|
||||||
|
if verbosity:
|
||||||
|
args.append(verbosity)
|
||||||
|
result = testdir.runpytest(*args)
|
||||||
|
out = result.stdout.str()
|
||||||
|
if verbosity == "-v":
|
||||||
|
assert "scheduling tests" in out
|
||||||
|
assert "gw" in out
|
||||||
|
elif verbosity == "-q":
|
||||||
|
assert "scheduling tests" not in out
|
||||||
|
assert "gw" not in out
|
||||||
|
assert "bringing up nodes..." in out
|
||||||
|
else:
|
||||||
|
assert "scheduling tests" not in out
|
||||||
|
assert "gw" in out
|
||||||
|
|
||||||
def test_pass_skip_fail(self, testdir):
|
def test_pass_skip_fail(self, testdir):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
@@ -400,64 +425,6 @@ class TestTerminalReporting:
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@pytest.mark.parametrize("n", ["-n0", "-n1"])
|
|
||||||
@pytest.mark.parametrize("warn_type", ["pytest", "builtin"])
|
|
||||||
def test_warnings(self, testdir, n, warn_type):
|
|
||||||
from pkg_resources import parse_version
|
|
||||||
|
|
||||||
if parse_version(pytest.__version__) < parse_version("3.1"):
|
|
||||||
pytest.skip("pytest warnings requires >= 3.1")
|
|
||||||
|
|
||||||
if warn_type == "builtin":
|
|
||||||
warn_code = """warnings.warn(UserWarning('this is a warning'))"""
|
|
||||||
elif warn_type == "pytest":
|
|
||||||
warn_code = """request.config.warn('', 'this is a warning',
|
|
||||||
fslocation=py.path.local())"""
|
|
||||||
else:
|
|
||||||
assert False
|
|
||||||
testdir.makepyfile(
|
|
||||||
"""
|
|
||||||
import warnings, py, pytest
|
|
||||||
|
|
||||||
@pytest.mark.filterwarnings('ignore:config.warn has been deprecated')
|
|
||||||
def test_func(request):
|
|
||||||
{warn_code}
|
|
||||||
""".format(
|
|
||||||
warn_code=warn_code
|
|
||||||
)
|
|
||||||
)
|
|
||||||
result = testdir.runpytest(n)
|
|
||||||
result.stdout.fnmatch_lines(["*this is a warning*", "*1 passed, 1 warnings*"])
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("n", ["-n0", "-n1"])
|
|
||||||
def test_custom_subclass(self, testdir, n):
|
|
||||||
"""Check that warning subclasses that don't honor the args attribute don't break
|
|
||||||
pytest-xdist (#344)
|
|
||||||
"""
|
|
||||||
from pkg_resources import parse_version
|
|
||||||
|
|
||||||
if parse_version(pytest.__version__) < parse_version("3.1"):
|
|
||||||
pytest.skip("pytest warnings requires >= 3.1")
|
|
||||||
|
|
||||||
testdir.makepyfile(
|
|
||||||
"""
|
|
||||||
import warnings, py, pytest
|
|
||||||
|
|
||||||
class MyWarning(UserWarning):
|
|
||||||
|
|
||||||
def __init__(self, p1, p2):
|
|
||||||
self.p1 = p1
|
|
||||||
self.p2 = p2
|
|
||||||
self.args = ()
|
|
||||||
|
|
||||||
def test_func(request):
|
|
||||||
warnings.warn(MyWarning("foo", 1))
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
testdir.syspathinsert()
|
|
||||||
result = testdir.runpytest(n)
|
|
||||||
result.stdout.fnmatch_lines(["*MyWarning*", "*1 passed, 1 warnings*"])
|
|
||||||
|
|
||||||
def test_logfinish_hook(self, testdir):
|
def test_logfinish_hook(self, testdir):
|
||||||
"""Ensure the pytest_runtest_logfinish hook is being properly handled"""
|
"""Ensure the pytest_runtest_logfinish hook is being properly handled"""
|
||||||
from _pytest import hookspec
|
from _pytest import hookspec
|
||||||
@@ -523,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)
|
||||||
@@ -575,16 +541,15 @@ def test_session_testscollected(testdir):
|
|||||||
assert collected_file.read() == "collected = 3"
|
assert collected_file.read() == "collected = 3"
|
||||||
|
|
||||||
|
|
||||||
def test_funcarg_teardown_failure(testdir):
|
def test_fixture_teardown_failure(testdir):
|
||||||
p = testdir.makepyfile(
|
p = testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
import pytest
|
import pytest
|
||||||
@pytest.fixture
|
@pytest.fixture(scope="module")
|
||||||
def myarg(request):
|
def myarg(request):
|
||||||
def teardown(val):
|
yield 42
|
||||||
raise ValueError(val)
|
raise ValueError(42)
|
||||||
return request.cached_setup(setup=lambda: 42, teardown=teardown,
|
|
||||||
scope="module")
|
|
||||||
def test_hello(myarg):
|
def test_hello(myarg):
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
@@ -670,6 +635,11 @@ def test_skipping(testdir):
|
|||||||
|
|
||||||
|
|
||||||
def test_issue34_pluginloading_in_subprocess(testdir):
|
def test_issue34_pluginloading_in_subprocess(testdir):
|
||||||
|
import _pytest.hookspec
|
||||||
|
|
||||||
|
if not hasattr(_pytest.hookspec, "pytest_namespace"):
|
||||||
|
pytest.skip("this pytest version no longer supports pytest_namespace()")
|
||||||
|
|
||||||
testdir.tmpdir.join("plugin123.py").write(
|
testdir.tmpdir.join("plugin123.py").write(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""
|
"""
|
||||||
@@ -765,6 +735,108 @@ def test_sub_plugins_disabled(testdir, plugin):
|
|||||||
result.stdout.fnmatch_lines("*1 passed*")
|
result.stdout.fnmatch_lines("*1 passed*")
|
||||||
|
|
||||||
|
|
||||||
|
class TestWarnings:
|
||||||
|
@pytest.mark.parametrize("n", ["-n0", "-n1"])
|
||||||
|
@pytest.mark.parametrize("warn_type", ["pytest", "builtin"])
|
||||||
|
def test_warnings(self, testdir, n, request, warn_type):
|
||||||
|
if warn_type == "builtin":
|
||||||
|
warn_code = """warnings.warn(UserWarning('this is a warning'))"""
|
||||||
|
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',
|
||||||
|
fslocation=py.path.local())"""
|
||||||
|
else:
|
||||||
|
assert False
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
import warnings, py, pytest
|
||||||
|
|
||||||
|
@pytest.mark.filterwarnings('ignore:config.warn has been deprecated')
|
||||||
|
def test_func(request):
|
||||||
|
{warn_code}
|
||||||
|
""".format(
|
||||||
|
warn_code=warn_code
|
||||||
|
)
|
||||||
|
)
|
||||||
|
result = testdir.runpytest(n)
|
||||||
|
result.stdout.fnmatch_lines(["*this is a warning*", "*1 passed, 1 warnings*"])
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("n", ["-n0", "-n1"])
|
||||||
|
def test_custom_subclass(self, testdir, n):
|
||||||
|
"""Check that warning subclasses that don't honor the args attribute don't break
|
||||||
|
pytest-xdist (#344)
|
||||||
|
"""
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
import warnings, py, pytest
|
||||||
|
|
||||||
|
class MyWarning(UserWarning):
|
||||||
|
|
||||||
|
def __init__(self, p1, p2):
|
||||||
|
self.p1 = p1
|
||||||
|
self.p2 = p2
|
||||||
|
self.args = ()
|
||||||
|
|
||||||
|
def test_func(request):
|
||||||
|
warnings.warn(MyWarning("foo", 1))
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
testdir.syspathinsert()
|
||||||
|
result = testdir.runpytest(n)
|
||||||
|
result.stdout.fnmatch_lines(["*MyWarning*", "*1 passed, 1 warnings*"])
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("n", ["-n0", "-n1"])
|
||||||
|
def test_unserializable_arguments(self, testdir, n):
|
||||||
|
"""Check that warnings with unserializable arguments are handled correctly (#349)."""
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
import warnings, pytest
|
||||||
|
|
||||||
|
def test_func(tmpdir):
|
||||||
|
fn = (tmpdir / 'foo.txt').ensure(file=1)
|
||||||
|
with fn.open('r') as f:
|
||||||
|
warnings.warn(UserWarning("foo", f))
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
testdir.syspathinsert()
|
||||||
|
result = testdir.runpytest(n)
|
||||||
|
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):
|
||||||
f = testdir.makepyfile(
|
f = testdir.makepyfile(
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import py
|
import py
|
||||||
|
import pytest
|
||||||
|
from pkg_resources import parse_version
|
||||||
|
|
||||||
from xdist.looponfail import RemoteControl
|
from xdist.looponfail import RemoteControl
|
||||||
from xdist.looponfail import StatRecorder
|
from xdist.looponfail import StatRecorder
|
||||||
|
|
||||||
@@ -214,7 +217,11 @@ class TestLooponFailing:
|
|||||||
assert "test_one" not in remotecontrol.failures[0]
|
assert "test_one" not in remotecontrol.failures[0]
|
||||||
assert "test_two" in remotecontrol.failures[0]
|
assert "test_two" in remotecontrol.failures[0]
|
||||||
|
|
||||||
@py.test.mark.xfail(py.test.__version__ >= "3.1", reason="broken by pytest 3.1+")
|
@pytest.mark.xfail(
|
||||||
|
parse_version(pytest.__version__) >= parse_version("3.1"),
|
||||||
|
reason="broken by pytest 3.1+",
|
||||||
|
strict=True,
|
||||||
|
)
|
||||||
def test_looponfail_removed_test(self, testdir):
|
def test_looponfail_removed_test(self, testdir):
|
||||||
modcol = testdir.getmodulecol(
|
modcol = testdir.getmodulecol(
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import py
|
import py
|
||||||
import pprint
|
import pprint
|
||||||
import pytest
|
import pytest
|
||||||
from xdist.workermanage import WorkerController, unserialize_report
|
import sys
|
||||||
from xdist.remote import serialize_report
|
|
||||||
|
from xdist.workermanage import WorkerController
|
||||||
import execnet
|
import execnet
|
||||||
import marshal
|
import marshal
|
||||||
|
|
||||||
@@ -79,188 +80,17 @@ def test_remoteinitconfig(testdir):
|
|||||||
assert config2.pluginmanager.getplugin("terminal") in (-1, None)
|
assert config2.pluginmanager.getplugin("terminal") in (-1, None)
|
||||||
|
|
||||||
|
|
||||||
class TestReportSerialization:
|
|
||||||
def test_xdist_longrepr_to_str_issue_241(self, testdir):
|
|
||||||
testdir.makepyfile(
|
|
||||||
"""
|
|
||||||
import os
|
|
||||||
def test_a(): assert False
|
|
||||||
def test_b(): pass
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
testdir.makeconftest(
|
|
||||||
"""
|
|
||||||
def pytest_runtest_logreport(report):
|
|
||||||
print(report.longrepr)
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
res = testdir.runpytest("-n1", "-s")
|
|
||||||
res.stdout.fnmatch_lines(["*1 failed, 1 passed *"])
|
|
||||||
|
|
||||||
def test_xdist_report_longrepr_reprcrash_130(self, testdir):
|
|
||||||
reprec = testdir.inline_runsource(
|
|
||||||
"""
|
|
||||||
import py
|
|
||||||
def test_fail(): assert False, 'Expected Message'
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
reports = reprec.getreports("pytest_runtest_logreport")
|
|
||||||
assert len(reports) == 3
|
|
||||||
rep = reports[1]
|
|
||||||
added_section = ("Failure Metadata", str("metadata metadata"), "*")
|
|
||||||
rep.longrepr.sections.append(added_section)
|
|
||||||
d = serialize_report(rep)
|
|
||||||
check_marshallable(d)
|
|
||||||
a = unserialize_report("testreport", d)
|
|
||||||
# Check assembled == rep
|
|
||||||
assert a.__dict__.keys() == rep.__dict__.keys()
|
|
||||||
for key in rep.__dict__.keys():
|
|
||||||
if key != "longrepr":
|
|
||||||
assert getattr(a, key) == getattr(rep, key)
|
|
||||||
assert rep.longrepr.reprcrash.lineno == a.longrepr.reprcrash.lineno
|
|
||||||
assert rep.longrepr.reprcrash.message == a.longrepr.reprcrash.message
|
|
||||||
assert rep.longrepr.reprcrash.path == a.longrepr.reprcrash.path
|
|
||||||
assert rep.longrepr.reprtraceback.entrysep == a.longrepr.reprtraceback.entrysep
|
|
||||||
assert (
|
|
||||||
rep.longrepr.reprtraceback.extraline == a.longrepr.reprtraceback.extraline
|
|
||||||
)
|
|
||||||
assert rep.longrepr.reprtraceback.style == a.longrepr.reprtraceback.style
|
|
||||||
assert rep.longrepr.sections == a.longrepr.sections
|
|
||||||
# Missing section attribute PR171
|
|
||||||
assert added_section in a.longrepr.sections
|
|
||||||
|
|
||||||
def test_reprentries_serialization_170(self, testdir):
|
|
||||||
from _pytest._code.code import ReprEntry
|
|
||||||
|
|
||||||
reprec = testdir.inline_runsource(
|
|
||||||
"""
|
|
||||||
def test_repr_entry():
|
|
||||||
x = 0
|
|
||||||
assert x
|
|
||||||
""",
|
|
||||||
"--showlocals",
|
|
||||||
)
|
|
||||||
reports = reprec.getreports("pytest_runtest_logreport")
|
|
||||||
assert len(reports) == 3
|
|
||||||
rep = reports[1]
|
|
||||||
d = serialize_report(rep)
|
|
||||||
a = unserialize_report("testreport", d)
|
|
||||||
|
|
||||||
rep_entries = rep.longrepr.reprtraceback.reprentries
|
|
||||||
a_entries = a.longrepr.reprtraceback.reprentries
|
|
||||||
for i in range(len(a_entries)):
|
|
||||||
assert isinstance(rep_entries[i], ReprEntry)
|
|
||||||
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.message == a_entries[i].reprfileloc.message
|
|
||||||
)
|
|
||||||
assert rep_entries[i].reprfileloc.path == a_entries[i].reprfileloc.path
|
|
||||||
assert rep_entries[i].reprfuncargs.args == a_entries[i].reprfuncargs.args
|
|
||||||
assert rep_entries[i].reprlocals.lines == a_entries[i].reprlocals.lines
|
|
||||||
assert rep_entries[i].style == a_entries[i].style
|
|
||||||
|
|
||||||
def test_reprentries_serialization_196(self, testdir):
|
|
||||||
from _pytest._code.code import ReprEntryNative
|
|
||||||
|
|
||||||
reprec = testdir.inline_runsource(
|
|
||||||
"""
|
|
||||||
def test_repr_entry_native():
|
|
||||||
x = 0
|
|
||||||
assert x
|
|
||||||
""",
|
|
||||||
"--tb=native",
|
|
||||||
)
|
|
||||||
reports = reprec.getreports("pytest_runtest_logreport")
|
|
||||||
assert len(reports) == 3
|
|
||||||
rep = reports[1]
|
|
||||||
d = serialize_report(rep)
|
|
||||||
a = unserialize_report("testreport", d)
|
|
||||||
|
|
||||||
rep_entries = rep.longrepr.reprtraceback.reprentries
|
|
||||||
a_entries = a.longrepr.reprtraceback.reprentries
|
|
||||||
for i in range(len(a_entries)):
|
|
||||||
assert isinstance(rep_entries[i], ReprEntryNative)
|
|
||||||
assert rep_entries[i].lines == a_entries[i].lines
|
|
||||||
|
|
||||||
def test_itemreport_outcomes(self, testdir):
|
|
||||||
reprec = testdir.inline_runsource(
|
|
||||||
"""
|
|
||||||
import py
|
|
||||||
def test_pass(): pass
|
|
||||||
def test_fail(): 0/0
|
|
||||||
@py.test.mark.skipif("True")
|
|
||||||
def test_skip(): pass
|
|
||||||
def test_skip_imperative():
|
|
||||||
py.test.skip("hello")
|
|
||||||
@py.test.mark.xfail("True")
|
|
||||||
def test_xfail(): 0/0
|
|
||||||
def test_xfail_imperative():
|
|
||||||
py.test.xfail("hello")
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
reports = reprec.getreports("pytest_runtest_logreport")
|
|
||||||
assert len(reports) == 17 # with setup/teardown "passed" reports
|
|
||||||
for rep in reports:
|
|
||||||
d = serialize_report(rep)
|
|
||||||
check_marshallable(d)
|
|
||||||
newrep = unserialize_report("testreport", d)
|
|
||||||
assert newrep.passed == rep.passed
|
|
||||||
assert newrep.failed == rep.failed
|
|
||||||
assert newrep.skipped == rep.skipped
|
|
||||||
if newrep.skipped and not hasattr(newrep, "wasxfail"):
|
|
||||||
assert len(newrep.longrepr) == 3
|
|
||||||
assert newrep.outcome == rep.outcome
|
|
||||||
assert newrep.when == rep.when
|
|
||||||
assert newrep.keywords == rep.keywords
|
|
||||||
if rep.failed:
|
|
||||||
assert newrep.longreprtext == rep.longreprtext
|
|
||||||
|
|
||||||
def test_collectreport_passed(self, testdir):
|
|
||||||
reprec = testdir.inline_runsource("def test_func(): pass")
|
|
||||||
reports = reprec.getreports("pytest_collectreport")
|
|
||||||
for rep in reports:
|
|
||||||
d = serialize_report(rep)
|
|
||||||
check_marshallable(d)
|
|
||||||
newrep = unserialize_report("collectreport", d)
|
|
||||||
assert newrep.passed == rep.passed
|
|
||||||
assert newrep.failed == rep.failed
|
|
||||||
assert newrep.skipped == rep.skipped
|
|
||||||
|
|
||||||
def test_collectreport_fail(self, testdir):
|
|
||||||
reprec = testdir.inline_runsource("qwe abc")
|
|
||||||
reports = reprec.getreports("pytest_collectreport")
|
|
||||||
assert reports
|
|
||||||
for rep in reports:
|
|
||||||
d = serialize_report(rep)
|
|
||||||
check_marshallable(d)
|
|
||||||
newrep = unserialize_report("collectreport", d)
|
|
||||||
assert newrep.passed == rep.passed
|
|
||||||
assert newrep.failed == rep.failed
|
|
||||||
assert newrep.skipped == rep.skipped
|
|
||||||
if rep.failed:
|
|
||||||
assert newrep.longrepr == str(rep.longrepr)
|
|
||||||
|
|
||||||
def test_extended_report_deserialization(self, testdir):
|
|
||||||
reprec = testdir.inline_runsource("qwe abc")
|
|
||||||
reports = reprec.getreports("pytest_collectreport")
|
|
||||||
assert reports
|
|
||||||
for rep in reports:
|
|
||||||
rep.extra = True
|
|
||||||
d = serialize_report(rep)
|
|
||||||
check_marshallable(d)
|
|
||||||
newrep = unserialize_report("collectreport", d)
|
|
||||||
assert newrep.extra
|
|
||||||
assert newrep.passed == rep.passed
|
|
||||||
assert newrep.failed == rep.failed
|
|
||||||
assert newrep.skipped == rep.skipped
|
|
||||||
if rep.failed:
|
|
||||||
assert newrep.longrepr == str(rep.longrepr)
|
|
||||||
|
|
||||||
|
|
||||||
class TestWorkerInteractor:
|
class TestWorkerInteractor:
|
||||||
def test_basic_collect_and_runtests(self, worker):
|
@pytest.fixture
|
||||||
|
def unserialize_report(self, pytestconfig):
|
||||||
|
def unserialize(data):
|
||||||
|
return pytestconfig.hook.pytest_report_from_serializable(
|
||||||
|
config=pytestconfig, data=data
|
||||||
|
)
|
||||||
|
|
||||||
|
return unserialize
|
||||||
|
|
||||||
|
def test_basic_collect_and_runtests(self, worker, unserialize_report):
|
||||||
worker.testdir.makepyfile(
|
worker.testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
def test_func():
|
def test_func():
|
||||||
@@ -285,21 +115,18 @@ class TestWorkerInteractor:
|
|||||||
ev = worker.popevent("testreport") # setup
|
ev = worker.popevent("testreport") # setup
|
||||||
ev = worker.popevent("testreport")
|
ev = worker.popevent("testreport")
|
||||||
assert ev.name == "testreport"
|
assert ev.name == "testreport"
|
||||||
rep = unserialize_report(ev.name, ev.kwargs["data"])
|
rep = unserialize_report(ev.kwargs["data"])
|
||||||
assert rep.nodeid.endswith("::test_func")
|
assert rep.nodeid.endswith("::test_func")
|
||||||
assert rep.passed
|
assert rep.passed
|
||||||
assert rep.when == "call"
|
assert rep.when == "call"
|
||||||
ev = worker.popevent("workerfinished")
|
ev = worker.popevent("workerfinished")
|
||||||
assert "workeroutput" in ev.kwargs
|
assert "workeroutput" in ev.kwargs
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
def test_remote_collect_skip(self, worker, unserialize_report):
|
||||||
pytest.__version__ >= "3.0", reason="skip at module level illegal in pytest 3.0"
|
|
||||||
)
|
|
||||||
def test_remote_collect_skip(self, worker):
|
|
||||||
worker.testdir.makepyfile(
|
worker.testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
import py
|
import pytest
|
||||||
py.test.skip("hello")
|
pytest.skip("hello", allow_module_level=True)
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
worker.setup()
|
worker.setup()
|
||||||
@@ -307,26 +134,25 @@ class TestWorkerInteractor:
|
|||||||
assert not ev.kwargs
|
assert not ev.kwargs
|
||||||
ev = worker.popevent()
|
ev = worker.popevent()
|
||||||
assert ev.name == "collectreport"
|
assert ev.name == "collectreport"
|
||||||
ev = worker.popevent()
|
rep = unserialize_report(ev.kwargs["data"])
|
||||||
assert ev.name == "collectreport"
|
|
||||||
rep = unserialize_report(ev.name, ev.kwargs["data"])
|
|
||||||
assert rep.skipped
|
assert rep.skipped
|
||||||
|
assert rep.longrepr[2] == "Skipped: hello"
|
||||||
ev = worker.popevent("collectionfinish")
|
ev = worker.popevent("collectionfinish")
|
||||||
assert not ev.kwargs["ids"]
|
assert not ev.kwargs["ids"]
|
||||||
|
|
||||||
def test_remote_collect_fail(self, worker):
|
def test_remote_collect_fail(self, worker, unserialize_report):
|
||||||
worker.testdir.makepyfile("""aasd qwe""")
|
worker.testdir.makepyfile("""aasd qwe""")
|
||||||
worker.setup()
|
worker.setup()
|
||||||
ev = worker.popevent("collectionstart")
|
ev = worker.popevent("collectionstart")
|
||||||
assert not ev.kwargs
|
assert not ev.kwargs
|
||||||
ev = worker.popevent()
|
ev = worker.popevent()
|
||||||
assert ev.name == "collectreport"
|
assert ev.name == "collectreport"
|
||||||
rep = unserialize_report(ev.name, ev.kwargs["data"])
|
rep = unserialize_report(ev.kwargs["data"])
|
||||||
assert rep.failed
|
assert rep.failed
|
||||||
ev = worker.popevent("collectionfinish")
|
ev = worker.popevent("collectionfinish")
|
||||||
assert not ev.kwargs["ids"]
|
assert not ev.kwargs["ids"]
|
||||||
|
|
||||||
def test_runtests_all(self, worker):
|
def test_runtests_all(self, worker, unserialize_report):
|
||||||
worker.testdir.makepyfile(
|
worker.testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
def test_func(): pass
|
def test_func(): pass
|
||||||
@@ -348,7 +174,7 @@ class TestWorkerInteractor:
|
|||||||
for i in range(3): # setup/call/teardown
|
for i in range(3): # setup/call/teardown
|
||||||
ev = worker.popevent("testreport")
|
ev = worker.popevent("testreport")
|
||||||
assert ev.name == "testreport"
|
assert ev.name == "testreport"
|
||||||
rep = unserialize_report(ev.name, ev.kwargs["data"])
|
rep = unserialize_report(ev.kwargs["data"])
|
||||||
assert rep.nodeid.endswith(func)
|
assert rep.nodeid.endswith(func)
|
||||||
ev = worker.popevent("workerfinished")
|
ev = worker.popevent("workerfinished")
|
||||||
assert "workeroutput" in ev.kwargs
|
assert "workeroutput" in ev.kwargs
|
||||||
@@ -400,3 +226,64 @@ def test_remote_env_vars(testdir):
|
|||||||
)
|
)
|
||||||
result = testdir.runpytest("-n2", "--max-worker-restart=0")
|
result = testdir.runpytest("-n2", "--max-worker-restart=0")
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_inner_argv(testdir):
|
||||||
|
"""Test/document the behavior due to execnet using `python -c`."""
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def test_argv():
|
||||||
|
assert sys.argv == ["-c"]
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
result = testdir.runpytest("-n1")
|
||||||
|
assert result.ret == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_mainargv(testdir):
|
||||||
|
outer_argv = sys.argv
|
||||||
|
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
def test_mainargv(request):
|
||||||
|
assert request.config.workerinput["mainargv"] == {!r}
|
||||||
|
""".format(
|
||||||
|
outer_argv
|
||||||
|
)
|
||||||
|
)
|
||||||
|
result = testdir.runpytest("-n1")
|
||||||
|
assert result.ret == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_usage_prog(testdir, request):
|
||||||
|
if not hasattr(request.config._parser, "prog"):
|
||||||
|
pytest.skip("prog not available in config parser")
|
||||||
|
testdir.makeconftest(
|
||||||
|
"""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
config_parser = None
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def get_config_parser():
|
||||||
|
return config_parser
|
||||||
|
|
||||||
|
def pytest_configure(config):
|
||||||
|
global config_parser
|
||||||
|
config_parser = config._parser
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def test(get_config_parser, request):
|
||||||
|
get_config_parser._getparser().error("my_usage_error")
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
result = testdir.runpytest_subprocess("-n1")
|
||||||
|
assert result.ret == 1
|
||||||
|
result.stdout.fnmatch_lines(["*usage: *", "*error: my_usage_error"])
|
||||||
|
|||||||
24
tox.ini
24
tox.ini
@@ -1,34 +1,17 @@
|
|||||||
[tox]
|
[tox]
|
||||||
# if you change the envlist, please update .travis.yml file as well
|
|
||||||
envlist=
|
envlist=
|
||||||
linting
|
linting
|
||||||
py{27,34,35,36}-pytest{30,31,32,33,36,38}
|
py{27,34,35,36,37}-pytestlatest
|
||||||
py{27,36}-pytest36-pexpect
|
|
||||||
py{27,36}-pytest{master,features}
|
py{27,36}-pytest{master,features}
|
||||||
|
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
changedir=testing
|
|
||||||
passenv = USER USERNAME
|
passenv = USER USERNAME
|
||||||
deps =
|
deps =
|
||||||
pycmd
|
pytestlatest: pytest
|
||||||
# to avoid .eggs
|
|
||||||
setuptools_scm
|
|
||||||
pytest30: pytest~=3.0.5
|
|
||||||
pytest31: pytest~=3.1.0
|
|
||||||
pytest32: pytest~=3.2.0
|
|
||||||
pytest33: pytest~=3.3.0
|
|
||||||
pytest36: pytest~=3.6.0
|
|
||||||
pytest38: pytest~=3.8.0
|
|
||||||
pytestmaster: git+https://github.com/pytest-dev/pytest.git@master
|
pytestmaster: git+https://github.com/pytest-dev/pytest.git@master
|
||||||
pytestfeatures: git+https://github.com/pytest-dev/pytest.git@features
|
pytestfeatures: git+https://github.com/pytest-dev/pytest.git@features
|
||||||
pexpect: pexpect
|
|
||||||
filelock
|
filelock
|
||||||
platform=
|
|
||||||
pexpect: linux|darwin
|
|
||||||
commands=
|
commands=
|
||||||
# always clean to avoid code unmarshal mismatch on old python/pytest
|
|
||||||
py.cleanup -aq
|
|
||||||
pytest {posargs}
|
pytest {posargs}
|
||||||
|
|
||||||
[testenv:linting]
|
[testenv:linting]
|
||||||
@@ -51,7 +34,8 @@ commands =
|
|||||||
towncrier --version {posargs} --yes
|
towncrier --version {posargs} --yes
|
||||||
|
|
||||||
[pytest]
|
[pytest]
|
||||||
addopts = -rsfxX
|
addopts = -ra
|
||||||
|
testpaths = testing
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
max-line-length = 120
|
max-line-length = 120
|
||||||
|
|||||||
@@ -229,9 +229,10 @@ class DSession(object):
|
|||||||
if self.terminal and not self.sched.has_pending:
|
if self.terminal and not self.sched.has_pending:
|
||||||
self.trdist.ensure_show_status()
|
self.trdist.ensure_show_status()
|
||||||
self.terminal.write_line("")
|
self.terminal.write_line("")
|
||||||
self.terminal.write_line(
|
if self.config.option.verbose > 0:
|
||||||
"scheduling tests via %s" % (self.sched.__class__.__name__)
|
self.terminal.write_line(
|
||||||
)
|
"scheduling tests via %s" % (self.sched.__class__.__name__)
|
||||||
|
)
|
||||||
self.sched.schedule()
|
self.sched.schedule()
|
||||||
|
|
||||||
def worker_logstart(self, node, nodeid, location):
|
def worker_logstart(self, node, nodeid, location):
|
||||||
@@ -259,10 +260,10 @@ class DSession(object):
|
|||||||
def worker_collectreport(self, node, rep):
|
def worker_collectreport(self, node, rep):
|
||||||
"""Emitted when a node calls the pytest_collectreport hook.
|
"""Emitted when a node calls the pytest_collectreport hook.
|
||||||
|
|
||||||
Because we only need the report when there's a failure, as optimization
|
Because we only need the report when there's a failure/skip, as optimization
|
||||||
we only expect to receive failed reports from workers (#330).
|
we only expect to receive failed/skipped reports from workers (#330).
|
||||||
"""
|
"""
|
||||||
assert rep.failed
|
assert not rep.passed
|
||||||
self._failed_worker_collectreport(node, rep)
|
self._failed_worker_collectreport(node, rep)
|
||||||
|
|
||||||
def worker_logwarning(self, message, code, nodeid, fslocation):
|
def worker_logwarning(self, message, code, nodeid, fslocation):
|
||||||
@@ -344,8 +345,11 @@ class TerminalDistReporter(object):
|
|||||||
self.rewrite(self.getstatus())
|
self.rewrite(self.getstatus())
|
||||||
|
|
||||||
def getstatus(self):
|
def getstatus(self):
|
||||||
parts = ["%s %s" % (spec.id, self._status[spec.id]) for spec in self._specs]
|
if self.config.option.verbose >= 0:
|
||||||
return " / ".join(parts)
|
parts = ["%s %s" % (spec.id, self._status[spec.id]) for spec in self._specs]
|
||||||
|
return " / ".join(parts)
|
||||||
|
else:
|
||||||
|
return "bringing up nodes..."
|
||||||
|
|
||||||
def rewrite(self, line, newline=False):
|
def rewrite(self, line, newline=False):
|
||||||
pline = line + " " * max(self._lastlen - len(line), 0)
|
pline = line + " " * max(self._lastlen - len(line), 0)
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ def pytest_addoption(parser):
|
|||||||
def pytest_cmdline_main(config):
|
def pytest_cmdline_main(config):
|
||||||
|
|
||||||
if config.getoption("looponfail"):
|
if config.getoption("looponfail"):
|
||||||
usepdb = config.getoption("usepdb") # a core option
|
usepdb = config.getoption("usepdb", False) # a core option
|
||||||
if usepdb:
|
if usepdb:
|
||||||
raise pytest.UsageError("--pdb incompatible with --looponfail.")
|
raise pytest.UsageError("--pdb is incompatible with --looponfail.")
|
||||||
looponfail_main(config)
|
looponfail_main(config)
|
||||||
return 2 # looponfail only can get stop with ctrl-C anyway
|
return 2 # looponfail only can get stop with ctrl-C anyway
|
||||||
|
|
||||||
|
|||||||
@@ -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. """
|
||||||
|
|
||||||
|
|||||||
@@ -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",
|
||||||
@@ -126,12 +130,12 @@ def pytest_addoption(parser):
|
|||||||
)
|
)
|
||||||
parser.addini(
|
parser.addini(
|
||||||
"rsyncdirs",
|
"rsyncdirs",
|
||||||
"list of (relative) paths to be rsynced for" " remote distributed testing.",
|
"list of (relative) paths to be rsynced for remote distributed testing.",
|
||||||
type="pathlist",
|
type="pathlist",
|
||||||
)
|
)
|
||||||
parser.addini(
|
parser.addini(
|
||||||
"rsyncignore",
|
"rsyncignore",
|
||||||
"list of (relative) glob-style paths to be ignored " "for rsyncing.",
|
"list of (relative) glob-style paths to be ignored for rsyncing.",
|
||||||
type="pathlist",
|
type="pathlist",
|
||||||
)
|
)
|
||||||
parser.addini(
|
parser.addini(
|
||||||
@@ -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", False) # 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
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
113
xdist/remote.py
113
xdist/remote.py
@@ -10,8 +10,10 @@ 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
|
||||||
|
|
||||||
|
|
||||||
class WorkerInteractor(object):
|
class WorkerInteractor(object):
|
||||||
@@ -102,26 +104,35 @@ class WorkerInteractor(object):
|
|||||||
self.sendevent("logfinish", nodeid=nodeid, location=location)
|
self.sendevent("logfinish", nodeid=nodeid, location=location)
|
||||||
|
|
||||||
def pytest_runtest_logreport(self, report):
|
def pytest_runtest_logreport(self, report):
|
||||||
data = serialize_report(report)
|
data = self.config.hook.pytest_report_to_serializable(
|
||||||
|
config=self.config, report=report
|
||||||
|
)
|
||||||
data["item_index"] = self.item_index
|
data["item_index"] = self.item_index
|
||||||
data["worker_id"] = self.workerid
|
data["worker_id"] = self.workerid
|
||||||
assert self.session.items[self.item_index].nodeid == report.nodeid
|
assert self.session.items[self.item_index].nodeid == report.nodeid
|
||||||
self.sendevent("testreport", data=data)
|
self.sendevent("testreport", data=data)
|
||||||
|
|
||||||
def pytest_collectreport(self, report):
|
def pytest_collectreport(self, report):
|
||||||
# master only needs reports that failed, as optimization send only them instead (#330)
|
# send only reports that have not passed to master as optimization (#330)
|
||||||
if report.failed:
|
if not report.passed:
|
||||||
data = serialize_report(report)
|
data = self.config.hook.pytest_report_to_serializable(
|
||||||
|
config=self.config, report=report
|
||||||
|
)
|
||||||
self.sendevent("collectreport", data=data)
|
self.sendevent("collectreport", data=data)
|
||||||
|
|
||||||
def pytest_logwarning(self, message, code, nodeid, fslocation):
|
# the pytest_logwarning hook was deprecated since pytest 4.0
|
||||||
self.sendevent(
|
if hasattr(
|
||||||
"logwarning",
|
_pytest.hookspec, "pytest_logwarning"
|
||||||
message=message,
|
) and not _pytest.hookspec.pytest_logwarning.pytest_spec.get("warn_on_impl"):
|
||||||
code=code,
|
|
||||||
nodeid=nodeid,
|
def pytest_logwarning(self, message, code, nodeid, fslocation):
|
||||||
fslocation=str(fslocation),
|
self.sendevent(
|
||||||
)
|
"logwarning",
|
||||||
|
message=message,
|
||||||
|
code=code,
|
||||||
|
nodeid=nodeid,
|
||||||
|
fslocation=str(fslocation),
|
||||||
|
)
|
||||||
|
|
||||||
# the pytest_warning_captured hook was introduced in pytest 3.8
|
# the pytest_warning_captured hook was introduced in pytest 3.8
|
||||||
if hasattr(_pytest.hookspec, "pytest_warning_captured"):
|
if hasattr(_pytest.hookspec, "pytest_warning_captured"):
|
||||||
@@ -136,53 +147,19 @@ class WorkerInteractor(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def serialize_report(rep):
|
|
||||||
def disassembled_report(rep):
|
|
||||||
reprtraceback = rep.longrepr.reprtraceback.__dict__.copy()
|
|
||||||
reprcrash = rep.longrepr.reprcrash.__dict__.copy()
|
|
||||||
|
|
||||||
new_entries = []
|
|
||||||
for entry in reprtraceback["reprentries"]:
|
|
||||||
entry_data = {"type": type(entry).__name__, "data": entry.__dict__.copy()}
|
|
||||||
for key, value in entry_data["data"].items():
|
|
||||||
if hasattr(value, "__dict__"):
|
|
||||||
entry_data["data"][key] = value.__dict__.copy()
|
|
||||||
new_entries.append(entry_data)
|
|
||||||
|
|
||||||
reprtraceback["reprentries"] = new_entries
|
|
||||||
|
|
||||||
return {
|
|
||||||
"reprcrash": reprcrash,
|
|
||||||
"reprtraceback": reprtraceback,
|
|
||||||
"sections": rep.longrepr.sections,
|
|
||||||
}
|
|
||||||
|
|
||||||
import py
|
|
||||||
|
|
||||||
d = rep.__dict__.copy()
|
|
||||||
if hasattr(rep.longrepr, "toterminal"):
|
|
||||||
if hasattr(rep.longrepr, "reprtraceback") and hasattr(
|
|
||||||
rep.longrepr, "reprcrash"
|
|
||||||
):
|
|
||||||
d["longrepr"] = disassembled_report(rep)
|
|
||||||
else:
|
|
||||||
d["longrepr"] = str(rep.longrepr)
|
|
||||||
else:
|
|
||||||
d["longrepr"] = rep.longrepr
|
|
||||||
for name in d:
|
|
||||||
if isinstance(d[name], py.path.local):
|
|
||||||
d[name] = str(d[name])
|
|
||||||
elif name == "result":
|
|
||||||
d[name] = None # for now
|
|
||||||
return d
|
|
||||||
|
|
||||||
|
|
||||||
def serialize_warning_message(warning_message):
|
def serialize_warning_message(warning_message):
|
||||||
if isinstance(warning_message.message, Warning):
|
if isinstance(warning_message.message, Warning):
|
||||||
message_module = type(warning_message.message).__module__
|
message_module = type(warning_message.message).__module__
|
||||||
message_class_name = type(warning_message.message).__name__
|
message_class_name = type(warning_message.message).__name__
|
||||||
message_args = warning_message.message.args
|
|
||||||
message_str = str(warning_message.message)
|
message_str = str(warning_message.message)
|
||||||
|
# check now if we can serialize the warning arguments (#349)
|
||||||
|
# if not, we will just use the exception message on the master node
|
||||||
|
try:
|
||||||
|
dumps(warning_message.message.args)
|
||||||
|
except DumpError:
|
||||||
|
message_args = None
|
||||||
|
else:
|
||||||
|
message_args = warning_message.message.args
|
||||||
else:
|
else:
|
||||||
message_str = warning_message.message
|
message_str = warning_message.message
|
||||||
message_module = None
|
message_module = None
|
||||||
@@ -207,7 +184,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
|
||||||
|
|
||||||
|
|
||||||
@@ -241,18 +226,20 @@ 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.workerinput = workerinput
|
config.workerinput = workerinput
|
||||||
config.workeroutput = {}
|
config.workeroutput = {}
|
||||||
# TODO: deprecated name, backward compatibility only. Remove it in future
|
# TODO: deprecated name, backward compatibility only. Remove it in future
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from xdist.scheduler.each import EachScheduling # noqa
|
from xdist.scheduler.each import EachScheduling # noqa
|
||||||
from xdist.scheduler.load import LoadScheduling # noqa
|
from xdist.scheduler.load import LoadScheduling # noqa
|
||||||
|
from xdist.scheduler.loadfile import LoadFileScheduling # noqa
|
||||||
from xdist.scheduler.loadscope import LoadScopeScheduling # noqa
|
from xdist.scheduler.loadscope import LoadScopeScheduling # noqa
|
||||||
from xdist.scheduler.filescope import LoadFileScheduling # noqa
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from . import LoadScopeScheduling
|
from .loadscope import LoadScopeScheduling
|
||||||
from py.log import Producer
|
from py.log import Producer
|
||||||
|
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ class LoadScopeScheduling(object):
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"Unable to identify crashitem on a workload with " "pending items"
|
"Unable to identify crashitem on a workload with pending items"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Made uncompleted work unit available again
|
# Made uncompleted work unit available again
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from __future__ import print_function
|
|||||||
import fnmatch
|
import fnmatch
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import threading
|
import sys
|
||||||
|
|
||||||
import py
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
@@ -10,8 +10,6 @@ import execnet
|
|||||||
|
|
||||||
import xdist.remote
|
import xdist.remote
|
||||||
|
|
||||||
from _pytest import runner # XXX load dynamically
|
|
||||||
|
|
||||||
|
|
||||||
def parse_spec_config(config):
|
def parse_spec_config(config):
|
||||||
xspeclist = []
|
xspeclist = []
|
||||||
@@ -36,7 +34,6 @@ class NodeManager(object):
|
|||||||
|
|
||||||
def __init__(self, config, specs=None, defaultchdir="pyexecnetcache"):
|
def __init__(self, config, specs=None, defaultchdir="pyexecnetcache"):
|
||||||
self.config = config
|
self.config = config
|
||||||
self._nodesready = threading.Event()
|
|
||||||
self.trace = self.config.trace.get("nodemanager")
|
self.trace = self.config.trace.get("nodemanager")
|
||||||
self.group = execnet.Group()
|
self.group = execnet.Group()
|
||||||
if specs is None:
|
if specs is None:
|
||||||
@@ -203,7 +200,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
|
||||||
@@ -213,6 +216,7 @@ class WorkerController(object):
|
|||||||
"workercount": len(nodemanager.specs),
|
"workercount": len(nodemanager.specs),
|
||||||
"slaveid": gateway.id,
|
"slaveid": gateway.id,
|
||||||
"slavecount": len(nodemanager.specs),
|
"slavecount": len(nodemanager.specs),
|
||||||
|
"mainargv": sys.argv,
|
||||||
}
|
}
|
||||||
# TODO: deprecated name, backward compatibility only. Remove it in future
|
# TODO: deprecated name, backward compatibility only. Remove it in future
|
||||||
self.slaveinput = self.workerinput
|
self.slaveinput = self.workerinput
|
||||||
@@ -242,8 +246,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)
|
||||||
|
|
||||||
@@ -268,7 +277,7 @@ class WorkerController(object):
|
|||||||
if not self._down:
|
if not self._down:
|
||||||
try:
|
try:
|
||||||
self.sendcommand("shutdown")
|
self.sendcommand("shutdown")
|
||||||
except IOError:
|
except (IOError, OSError):
|
||||||
pass
|
pass
|
||||||
self._shutdown_sent = True
|
self._shutdown_sent = True
|
||||||
|
|
||||||
@@ -311,7 +320,9 @@ class WorkerController(object):
|
|||||||
self.notify_inproc(eventname, node=self, **kwargs)
|
self.notify_inproc(eventname, node=self, **kwargs)
|
||||||
elif eventname in ("testreport", "collectreport", "teardownreport"):
|
elif eventname in ("testreport", "collectreport", "teardownreport"):
|
||||||
item_index = kwargs.pop("item_index", None)
|
item_index = kwargs.pop("item_index", None)
|
||||||
rep = unserialize_report(eventname, kwargs["data"])
|
rep = self.config.hook.pytest_report_from_serializable(
|
||||||
|
config=self.config, data=kwargs["data"]
|
||||||
|
)
|
||||||
if item_index is not None:
|
if item_index is not None:
|
||||||
rep.item_index = item_index
|
rep.item_index = item_index
|
||||||
self.notify_inproc(eventname, node=self, rep=rep)
|
self.notify_inproc(eventname, node=self, rep=rep)
|
||||||
@@ -345,80 +356,17 @@ class WorkerController(object):
|
|||||||
except: # noqa
|
except: # noqa
|
||||||
from _pytest._code import ExceptionInfo
|
from _pytest._code import ExceptionInfo
|
||||||
|
|
||||||
excinfo = ExceptionInfo()
|
# ExceptionInfo API changed in pytest 4.1
|
||||||
|
if hasattr(ExceptionInfo, "from_current"):
|
||||||
|
excinfo = ExceptionInfo.from_current()
|
||||||
|
else:
|
||||||
|
excinfo = ExceptionInfo()
|
||||||
print("!" * 20, excinfo)
|
print("!" * 20, excinfo)
|
||||||
self.config.notify_exception(excinfo)
|
self.config.notify_exception(excinfo)
|
||||||
self.shutdown()
|
self.shutdown()
|
||||||
self.notify_inproc("errordown", node=self, error=excinfo)
|
self.notify_inproc("errordown", node=self, error=excinfo)
|
||||||
|
|
||||||
|
|
||||||
def unserialize_report(name, reportdict):
|
|
||||||
def assembled_report(reportdict):
|
|
||||||
from _pytest._code.code import (
|
|
||||||
ReprEntry,
|
|
||||||
ReprEntryNative,
|
|
||||||
ReprExceptionInfo,
|
|
||||||
ReprFileLocation,
|
|
||||||
ReprFuncArgs,
|
|
||||||
ReprLocals,
|
|
||||||
ReprTraceback,
|
|
||||||
)
|
|
||||||
|
|
||||||
if reportdict["longrepr"]:
|
|
||||||
if (
|
|
||||||
"reprcrash" in reportdict["longrepr"]
|
|
||||||
and "reprtraceback" in reportdict["longrepr"]
|
|
||||||
):
|
|
||||||
|
|
||||||
reprtraceback = reportdict["longrepr"]["reprtraceback"]
|
|
||||||
reprcrash = reportdict["longrepr"]["reprcrash"]
|
|
||||||
|
|
||||||
unserialized_entries = []
|
|
||||||
reprentry = None
|
|
||||||
for entry_data in reprtraceback["reprentries"]:
|
|
||||||
data = entry_data["data"]
|
|
||||||
entry_type = entry_data["type"]
|
|
||||||
if entry_type == "ReprEntry":
|
|
||||||
reprfuncargs = None
|
|
||||||
reprfileloc = None
|
|
||||||
reprlocals = None
|
|
||||||
if data["reprfuncargs"]:
|
|
||||||
reprfuncargs = ReprFuncArgs(**data["reprfuncargs"])
|
|
||||||
if data["reprfileloc"]:
|
|
||||||
reprfileloc = ReprFileLocation(**data["reprfileloc"])
|
|
||||||
if data["reprlocals"]:
|
|
||||||
reprlocals = ReprLocals(data["reprlocals"]["lines"])
|
|
||||||
|
|
||||||
reprentry = ReprEntry(
|
|
||||||
lines=data["lines"],
|
|
||||||
reprfuncargs=reprfuncargs,
|
|
||||||
reprlocals=reprlocals,
|
|
||||||
filelocrepr=reprfileloc,
|
|
||||||
style=data["style"],
|
|
||||||
)
|
|
||||||
elif entry_type == "ReprEntryNative":
|
|
||||||
reprentry = ReprEntryNative(data["lines"])
|
|
||||||
else:
|
|
||||||
report_unserialization_failure(entry_type, name, reportdict)
|
|
||||||
unserialized_entries.append(reprentry)
|
|
||||||
reprtraceback["reprentries"] = unserialized_entries
|
|
||||||
|
|
||||||
exception_info = ReprExceptionInfo(
|
|
||||||
reprtraceback=ReprTraceback(**reprtraceback),
|
|
||||||
reprcrash=ReprFileLocation(**reprcrash),
|
|
||||||
)
|
|
||||||
|
|
||||||
for section in reportdict["longrepr"]["sections"]:
|
|
||||||
exception_info.addsection(*section)
|
|
||||||
reportdict["longrepr"] = exception_info
|
|
||||||
return reportdict
|
|
||||||
|
|
||||||
if name == "testreport":
|
|
||||||
return runner.TestReport(**assembled_report(reportdict))
|
|
||||||
elif name == "collectreport":
|
|
||||||
return runner.CollectReport(**assembled_report(reportdict))
|
|
||||||
|
|
||||||
|
|
||||||
def unserialize_warning_message(data):
|
def unserialize_warning_message(data):
|
||||||
import warnings
|
import warnings
|
||||||
import importlib
|
import importlib
|
||||||
@@ -426,9 +374,16 @@ def unserialize_warning_message(data):
|
|||||||
if data["message_module"]:
|
if data["message_module"]:
|
||||||
mod = importlib.import_module(data["message_module"])
|
mod = importlib.import_module(data["message_module"])
|
||||||
cls = getattr(mod, data["message_class_name"])
|
cls = getattr(mod, data["message_class_name"])
|
||||||
try:
|
message = None
|
||||||
message = cls(*data["message_args"])
|
if data["message_args"] is not None:
|
||||||
except TypeError:
|
try:
|
||||||
|
message = cls(*data["message_args"])
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
if message is None:
|
||||||
|
# could not recreate the original warning instance;
|
||||||
|
# create a generic Warning instance with the original
|
||||||
|
# message at least
|
||||||
message_text = "{mod}.{cls}: {msg}".format(
|
message_text = "{mod}.{cls}: {msg}".format(
|
||||||
mod=data["message_module"],
|
mod=data["message_module"],
|
||||||
cls=data["message_class_name"],
|
cls=data["message_class_name"],
|
||||||
@@ -452,17 +407,3 @@ def unserialize_warning_message(data):
|
|||||||
kwargs[attr_name] = data[attr_name]
|
kwargs[attr_name] = data[attr_name]
|
||||||
|
|
||||||
return warnings.WarningMessage(**kwargs)
|
return warnings.WarningMessage(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
def report_unserialization_failure(type_name, report_name, reportdict):
|
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
url = "https://github.com/pytest-dev/pytest-xdist/issues"
|
|
||||||
stream = py.io.TextIO()
|
|
||||||
pprint("-" * 100, stream=stream)
|
|
||||||
pprint("INTERNALERROR: Unknown entry type returned: %s" % type_name, stream=stream)
|
|
||||||
pprint("report_name: %s" % report_name, stream=stream)
|
|
||||||
pprint(reportdict, stream=stream)
|
|
||||||
pprint("Please report this bug at %s" % url, stream=stream)
|
|
||||||
pprint("-" * 100, stream=stream)
|
|
||||||
assert 0, stream.getvalue()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user