Compare commits
70 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b487ed5e1 | ||
|
|
ecf4d3be31 | ||
|
|
87d89795e3 | ||
|
|
b4544c8849 | ||
|
|
66dc3904b4 | ||
|
|
e0ce1b7418 | ||
|
|
ed47f0e01a | ||
|
|
1c8178abc5 | ||
|
|
9807064f66 | ||
|
|
766e67ce52 | ||
|
|
305aeeacec | ||
|
|
90fc616906 | ||
|
|
5f4d6ea0e6 | ||
|
|
a0ad5cf041 | ||
|
|
5e0b40cea2 | ||
|
|
513e203ee1 | ||
|
|
a5c65dd1e4 | ||
|
|
ccb14f24fc | ||
|
|
76dbde0475 | ||
|
|
1167e1609c | ||
|
|
348a956724 | ||
|
|
dba716ba91 | ||
|
|
e7c42f0b3b | ||
|
|
fe57b39563 | ||
|
|
26e7d953f4 | ||
|
|
b02a6db771 | ||
|
|
b0722675e0 | ||
|
|
881cc48271 | ||
|
|
958679e9a7 | ||
|
|
7f07d50808 | ||
|
|
fb518def55 | ||
|
|
0b14d92894 | ||
|
|
02f971d45f | ||
|
|
56e631b4bb | ||
|
|
7f2426b11d | ||
|
|
0c84201b40 | ||
|
|
08d8a62040 | ||
|
|
f36ee80e8c | ||
|
|
f75479f7f3 | ||
|
|
10ec3af8a0 | ||
|
|
577e24b5bd | ||
|
|
e37039ee41 | ||
|
|
cc828ddbfc | ||
|
|
4f459aa119 | ||
|
|
3a7604bdb7 | ||
|
|
d4d01bba2e | ||
|
|
4d27110beb | ||
|
|
260211603e | ||
|
|
f861f1667d | ||
|
|
f5665436e9 | ||
|
|
8b35945d54 | ||
|
|
3fe2094197 | ||
|
|
04dde88996 | ||
|
|
9785a316ae | ||
|
|
1dc019709c | ||
|
|
d909dcc61f | ||
|
|
f02aa70c95 | ||
|
|
1637dc18d0 | ||
|
|
f5342962ab | ||
|
|
1189ae4b91 | ||
|
|
89c86af894 | ||
|
|
b239199061 | ||
|
|
9e4e8b74e0 | ||
|
|
166bdb4103 | ||
|
|
e4bcbbee78 | ||
|
|
f6308cad01 | ||
|
|
aa89c42ad7 | ||
|
|
40fa7b091d | ||
|
|
ad99d943de | ||
|
|
0d2480f7e3 |
44
.github/workflows/main.yml
vendored
44
.github/workflows/main.yml
vendored
@@ -11,19 +11,17 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
tox_env:
|
||||
- "py35-pytestlatest"
|
||||
- "py36-pytestlatest"
|
||||
- "py37-pytestlatest"
|
||||
- "py38-pytestlatest"
|
||||
- "py39-pytestlatest"
|
||||
- "py38-pytestmaster"
|
||||
- "py310-pytestlatest"
|
||||
- "py38-pytestmain"
|
||||
- "py38-psutil"
|
||||
- "linting"
|
||||
- "py38-setproctitle"
|
||||
|
||||
os: [ubuntu-latest, windows-latest]
|
||||
include:
|
||||
- tox_env: "py35-pytestlatest"
|
||||
python: "3.5"
|
||||
- tox_env: "py36-pytestlatest"
|
||||
python: "3.6"
|
||||
- tox_env: "py37-pytestlatest"
|
||||
@@ -32,17 +30,19 @@ jobs:
|
||||
python: "3.8"
|
||||
- tox_env: "py39-pytestlatest"
|
||||
python: "3.9"
|
||||
- tox_env: "py38-pytestmaster"
|
||||
- tox_env: "py310-pytestlatest"
|
||||
python: "3.10-dev"
|
||||
- tox_env: "py38-pytestmain"
|
||||
python: "3.8"
|
||||
- tox_env: "py38-psutil"
|
||||
python: "3.8"
|
||||
- tox_env: "linting"
|
||||
python: "3.7"
|
||||
- tox_env: "py38-setproctitle"
|
||||
python: "3.8"
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v1
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python }}
|
||||
- name: Install tox
|
||||
@@ -53,36 +53,18 @@ jobs:
|
||||
run: |
|
||||
tox -e ${{ matrix.tox_env }}
|
||||
|
||||
linting:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: "3.7"
|
||||
- name: Install tox
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install tox
|
||||
- name: Linting
|
||||
run: |
|
||||
tox -e linting
|
||||
|
||||
deploy:
|
||||
|
||||
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
needs: [build, linting]
|
||||
needs: build
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v1
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: "3.7"
|
||||
- name: Install wheel
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
repos:
|
||||
- repo: https://github.com/ambv/black
|
||||
rev: 19.10b0
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 21.9b0
|
||||
hooks:
|
||||
- id: black
|
||||
args: [--safe, --quiet, --target-version, py35]
|
||||
language_version: python3.7
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v2.4.0
|
||||
rev: v4.0.1
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
- id: check-yaml
|
||||
- id: debug-statements
|
||||
- repo: https://github.com/PyCQA/flake8
|
||||
rev: 3.9.2
|
||||
hooks:
|
||||
- id: flake8
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v2.7.2
|
||||
rev: v2.26.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: [--py3-plus]
|
||||
|
||||
@@ -1,3 +1,60 @@
|
||||
pytest-xdist 2.4.0 (2021-09-20)
|
||||
===============================
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
- `#696 <https://github.com/pytest-dev/pytest-xdist/issues/696>`_: On Linux, the process title now changes to indicate the current worker state (running/idle).
|
||||
|
||||
Depends on the `setproctitle <https://pypi.org/project/setproctitle/>`__ package, which can be installed with ``pip install pytest-xdist[setproctitle]``.
|
||||
|
||||
- `#704 <https://github.com/pytest-dev/pytest-xdist/issues/704>`_: Add support for Python 3.10.
|
||||
|
||||
|
||||
pytest-xdist 2.3.0 (2021-06-16)
|
||||
===============================
|
||||
|
||||
Deprecations and Removals
|
||||
-------------------------
|
||||
|
||||
- `#654 <https://github.com/pytest-dev/pytest-xdist/issues/654>`_: Python 3.5 is no longer supported.
|
||||
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
- `#646 <https://github.com/pytest-dev/pytest-xdist/issues/646>`_: Add ``--numprocesses=logical`` flag, which automatically uses the number of logical CPUs available, instead of physical CPUs with ``auto``.
|
||||
|
||||
This is very useful for test suites which are not CPU-bound.
|
||||
|
||||
- `#650 <https://github.com/pytest-dev/pytest-xdist/issues/650>`_: Added new ``pytest_handlecrashitem`` hook to allow handling and rescheduling crashed items.
|
||||
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
- `#421 <https://github.com/pytest-dev/pytest-xdist/issues/421>`_: Copy the parent process sys.path into local workers, to work around execnet's python -c adding the current directory to sys.path.
|
||||
|
||||
- `#638 <https://github.com/pytest-dev/pytest-xdist/issues/638>`_: Fix issue caused by changing the branch name of the pytest repository.
|
||||
|
||||
|
||||
Trivial Changes
|
||||
---------------
|
||||
|
||||
- `#592 <https://github.com/pytest-dev/pytest-xdist/issues/592>`_: Replace master with controller where ever possible.
|
||||
|
||||
- `#643 <https://github.com/pytest-dev/pytest-xdist/issues/643>`_: Use 'main' to refer to pytest default branch in tox env names.
|
||||
|
||||
|
||||
pytest-xdist 2.2.1 (2021-02-09)
|
||||
===============================
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
- `#623 <https://github.com/pytest-dev/pytest-xdist/issues/623>`_: Gracefully handle the pending deprecation of Node.fspath by using config.rootpath for topdir.
|
||||
|
||||
|
||||
pytest-xdist 2.2.0 (2020-12-14)
|
||||
===============================
|
||||
|
||||
|
||||
48
README.rst
48
README.rst
@@ -45,6 +45,9 @@ If you would like to know how pytest-xdist works under the covers, checkout
|
||||
`OVERVIEW <https://github.com/pytest-dev/pytest-xdist/blob/master/OVERVIEW.md>`_.
|
||||
|
||||
|
||||
**NOTE**: due to how pytest-xdist is implemented, the ``-s/--capture=no`` option does not work.
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
@@ -149,16 +152,16 @@ where executing a high-scope fixture exactly once is important.
|
||||
Running tests in a Python subprocess
|
||||
------------------------------------
|
||||
|
||||
To instantiate a python3.5 subprocess and send tests to it, you may type::
|
||||
To instantiate a python3.9 subprocess and send tests to it, you may type::
|
||||
|
||||
pytest -d --tx popen//python=python3.5
|
||||
pytest -d --tx popen//python=python3.9
|
||||
|
||||
This will start a subprocess which is run with the ``python3.5``
|
||||
This will start a subprocess which is run with the ``python3.9``
|
||||
Python interpreter, found in your system binary lookup path.
|
||||
|
||||
If you prefix the --tx option value like this::
|
||||
|
||||
--tx 3*popen//python=python3.5
|
||||
--tx 3*popen//python=python3.9
|
||||
|
||||
then three subprocesses would be created and tests
|
||||
will be load-balanced across these three processes.
|
||||
@@ -285,7 +288,18 @@ Since version 2.0, the following functions are also available in the ``xdist`` m
|
||||
"""
|
||||
|
||||
def is_xdist_master(request_or_session) -> bool:
|
||||
"""Return `True` if this is the xdist master, `False` otherwise
|
||||
"""Return `True` if this is the xdist controller, `False` otherwise
|
||||
|
||||
Note: this method also returns `False` when distribution has not been
|
||||
activated at all.
|
||||
|
||||
deprecated alias for is_xdist_controller
|
||||
|
||||
:param request_or_session: the `pytest` `request` or `session` object
|
||||
"""
|
||||
|
||||
def is_xdist_controller(request_or_session) -> bool:
|
||||
"""Return `True` if this is the xdist controller, `False` otherwise
|
||||
|
||||
Note: this method also returns `False` when distribution has not been
|
||||
activated at all.
|
||||
@@ -295,7 +309,7 @@ Since version 2.0, the following functions are also available in the ``xdist`` m
|
||||
|
||||
def get_xdist_worker_id(request_or_session) -> str:
|
||||
"""Return the id of the current worker ('gw0', 'gw1', etc) or 'master'
|
||||
if running on the 'master' node.
|
||||
if running on the controller node.
|
||||
|
||||
If not distributing tests (for example passing `-n0` or not passing `-n` at all) also return 'master'.
|
||||
|
||||
@@ -303,6 +317,26 @@ Since version 2.0, the following functions are also available in the ``xdist`` m
|
||||
"""
|
||||
|
||||
|
||||
Identifying workers from the system environment
|
||||
-----------------------------------------------
|
||||
|
||||
*New in version UNRELEASED TBD FIXME*
|
||||
|
||||
If the `setproctitle`_ package is installed, ``pytest-xdist`` will use it to
|
||||
update the process title (command line) on its workers to show their current
|
||||
state. The titles used are ``[pytest-xdist running] file.py/node::id`` and
|
||||
``[pytest-xdist idle]``, visible in standard tools like ``ps`` and ``top`` on
|
||||
Linux, Mac OS X and BSD systems. For Windows, please follow `setproctitle`_'s
|
||||
pointer regarding the Process Explorer tool.
|
||||
|
||||
This is intended purely as an UX enhancement, e.g. to track down issues with
|
||||
long-running or CPU intensive tests. Errors in changing the title are ignored
|
||||
silently. Please try not to rely on the title format or title changes in
|
||||
external scripts.
|
||||
|
||||
.. _`setproctitle`: https://pypi.org/project/setproctitle/
|
||||
|
||||
|
||||
Uniquely identifying the current test run
|
||||
-----------------------------------------
|
||||
|
||||
@@ -360,7 +394,7 @@ You can also add default environments like this:
|
||||
.. code-block:: ini
|
||||
|
||||
[pytest]
|
||||
addopts = --tx ssh=myhost//python=python3.5 --tx ssh=myhost//python=python3.6
|
||||
addopts = --tx ssh=myhost//python=python3.9 --tx ssh=myhost//python=python3.6
|
||||
|
||||
and then just type::
|
||||
|
||||
|
||||
11
setup.py
11
setup.py
@@ -18,12 +18,16 @@ setup(
|
||||
platforms=["linux", "osx", "win32"],
|
||||
packages=find_packages(where="src"),
|
||||
package_dir={"": "src"},
|
||||
extras_require={"testing": ["filelock"], "psutil": ["psutil>=3.0"]},
|
||||
extras_require={
|
||||
"testing": ["filelock"],
|
||||
"psutil": ["psutil>=3.0"],
|
||||
"setproctitle": ["setproctitle"],
|
||||
},
|
||||
entry_points={
|
||||
"pytest11": ["xdist = xdist.plugin", "xdist.looponfail = xdist.looponfail"]
|
||||
},
|
||||
zip_safe=False,
|
||||
python_requires=">=3.5",
|
||||
python_requires=">=3.6",
|
||||
install_requires=install_requires,
|
||||
setup_requires=["setuptools_scm"],
|
||||
classifiers=[
|
||||
@@ -40,9 +44,10 @@ setup(
|
||||
"Programming Language :: Python",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3 :: Only",
|
||||
"Programming Language :: Python :: 3.5",
|
||||
"Programming Language :: Python :: 3.6",
|
||||
"Programming Language :: Python :: 3.7",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
from xdist.plugin import is_xdist_worker, is_xdist_master, get_xdist_worker_id
|
||||
from xdist.plugin import (
|
||||
is_xdist_worker,
|
||||
is_xdist_master,
|
||||
get_xdist_worker_id,
|
||||
is_xdist_controller,
|
||||
)
|
||||
from xdist._version import version as __version__
|
||||
|
||||
__all__ = ["__version__", "is_xdist_worker", "is_xdist_master", "get_xdist_worker_id"]
|
||||
__all__ = [
|
||||
"__version__",
|
||||
"is_xdist_worker",
|
||||
"is_xdist_master",
|
||||
"is_xdist_controller",
|
||||
"get_xdist_worker_id",
|
||||
]
|
||||
|
||||
@@ -14,7 +14,7 @@ from queue import Empty, Queue
|
||||
|
||||
|
||||
class Interrupted(KeyboardInterrupt):
|
||||
""" signals an immediate interruption. """
|
||||
"""signals an immediate interruption."""
|
||||
|
||||
|
||||
class DSession:
|
||||
@@ -87,7 +87,7 @@ class DSession:
|
||||
self._session = None
|
||||
|
||||
def pytest_collection(self):
|
||||
# prohibit collection of test items in master process
|
||||
# prohibit collection of test items in controller process
|
||||
return True
|
||||
|
||||
@pytest.mark.trylast
|
||||
@@ -240,7 +240,7 @@ class DSession:
|
||||
return
|
||||
self.config.hook.pytest_xdist_node_collection_finished(node=node, ids=ids)
|
||||
# tell session which items were effectively collected otherwise
|
||||
# the master node will finish the session with EXIT_NOTESTSCOLLECTED
|
||||
# the controller node will finish the session with EXIT_NOTESTSCOLLECTED
|
||||
self._session.testscollected = len(ids)
|
||||
self.sched.add_node_collection(node, ids)
|
||||
if self.terminal:
|
||||
@@ -343,6 +343,12 @@ class DSession:
|
||||
nodeid, (fspath, None, fspath), (), "failed", msg, "???"
|
||||
)
|
||||
rep.node = worker
|
||||
|
||||
self.config.hook.pytest_handlecrashitem(
|
||||
crashitem=nodeid,
|
||||
report=rep,
|
||||
sched=self.sched,
|
||||
)
|
||||
self.config.hook.pytest_runtest_logreport(report=rep)
|
||||
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class RemoteControl:
|
||||
|
||||
def trace(self, *args):
|
||||
if self.config.option.debug:
|
||||
msg = " ".join([str(x) for x in args])
|
||||
msg = " ".join(str(x) for x in args)
|
||||
print("RemoteControl:", msg)
|
||||
|
||||
def initgateway(self):
|
||||
|
||||
@@ -15,46 +15,45 @@ import pytest
|
||||
|
||||
|
||||
def pytest_xdist_setupnodes(config, specs):
|
||||
""" called before any remote node is set up. """
|
||||
"""called before any remote node is set up."""
|
||||
|
||||
|
||||
def pytest_xdist_newgateway(gateway):
|
||||
""" called on new raw gateway creation. """
|
||||
"""called on new raw gateway creation."""
|
||||
|
||||
|
||||
def pytest_xdist_rsyncstart(source, gateways):
|
||||
""" called before rsyncing a directory to remote gateways takes place. """
|
||||
"""called before rsyncing a directory to remote gateways takes place."""
|
||||
|
||||
|
||||
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"""
|
||||
"""called when creating remote node"""
|
||||
|
||||
|
||||
def pytest_configure_node(node):
|
||||
""" configure node information before it gets instantiated. """
|
||||
"""configure node information before it gets instantiated."""
|
||||
|
||||
|
||||
def pytest_testnodeready(node):
|
||||
""" Test Node is ready to operate. """
|
||||
"""Test Node is ready to operate."""
|
||||
|
||||
|
||||
def pytest_testnodedown(node, error):
|
||||
""" Test Node is down. """
|
||||
"""Test Node is down."""
|
||||
|
||||
|
||||
def pytest_xdist_node_collection_finished(node, ids):
|
||||
"""called by the master node when a node finishes collecting.
|
||||
"""
|
||||
"""called by the controller node when a worker node finishes collecting."""
|
||||
|
||||
|
||||
@pytest.mark.firstresult
|
||||
def pytest_xdist_make_scheduler(config, log):
|
||||
""" return a node scheduler implementation """
|
||||
"""return a node scheduler implementation"""
|
||||
|
||||
|
||||
@pytest.mark.firstresult
|
||||
@@ -65,3 +64,20 @@ def pytest_xdist_auto_num_workers(config):
|
||||
|
||||
.. versionadded:: 2.1
|
||||
"""
|
||||
|
||||
|
||||
@pytest.mark.firstresult
|
||||
def pytest_handlecrashitem(crashitem, report, sched):
|
||||
"""
|
||||
Handle a crashitem, modifying the report if necessary.
|
||||
|
||||
The scheduler is provided as a parameter to reschedule the test if desired with
|
||||
`sched.mark_test_pending`.
|
||||
|
||||
def pytest_handlecrashitem(crashitem, report, sched):
|
||||
if should_rerun(crashitem):
|
||||
sched.mark_test_pending(crashitem)
|
||||
report.outcome = "rerun"
|
||||
|
||||
.. versionadded:: 2.2.1
|
||||
"""
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
import os
|
||||
import uuid
|
||||
import sys
|
||||
|
||||
import py
|
||||
import pytest
|
||||
|
||||
_sys_path = list(sys.path) # freeze a copy of sys.path at interpreter startup
|
||||
|
||||
def pytest_xdist_auto_num_workers():
|
||||
|
||||
def pytest_xdist_auto_num_workers(config):
|
||||
try:
|
||||
import psutil
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
count = psutil.cpu_count(logical=False) or psutil.cpu_count()
|
||||
use_logical = config.option.numprocesses == "logical"
|
||||
count = psutil.cpu_count(logical=use_logical) or psutil.cpu_count()
|
||||
if count:
|
||||
return count
|
||||
try:
|
||||
@@ -36,8 +40,8 @@ def pytest_xdist_auto_num_workers():
|
||||
|
||||
|
||||
def parse_numprocesses(s):
|
||||
if s == "auto":
|
||||
return "auto"
|
||||
if s in ("auto", "logical"):
|
||||
return s
|
||||
elif s is not None:
|
||||
return int(s)
|
||||
|
||||
@@ -51,9 +55,10 @@ def pytest_addoption(parser):
|
||||
metavar="numprocesses",
|
||||
action="store",
|
||||
type=parse_numprocesses,
|
||||
help="shortcut for '--dist=load --tx=NUM*popen', "
|
||||
"you can use 'auto' here for auto detection CPUs number on "
|
||||
"host system and it will be 0 when used with --pdb",
|
||||
help="Shortcut for '--dist=load --tx=NUM*popen'. With 'auto', attempt "
|
||||
"to detect physical CPU count. With 'logical', detect logical CPU "
|
||||
"count. If physical CPU count cannot be found, falls back to logical "
|
||||
"count. This will be 0 when used with --pdb.",
|
||||
)
|
||||
group.addoption(
|
||||
"--maxprocesses",
|
||||
@@ -190,7 +195,7 @@ def pytest_configure(config):
|
||||
@pytest.mark.tryfirst
|
||||
def pytest_cmdline_main(config):
|
||||
usepdb = config.getoption("usepdb", False) # a core option
|
||||
if config.option.numprocesses == "auto":
|
||||
if config.option.numprocesses in ("auto", "logical"):
|
||||
if usepdb:
|
||||
config.option.numprocesses = 0
|
||||
config.option.dist = "no"
|
||||
@@ -227,8 +232,8 @@ def is_xdist_worker(request_or_session) -> bool:
|
||||
return hasattr(request_or_session.config, "workerinput")
|
||||
|
||||
|
||||
def is_xdist_master(request_or_session) -> bool:
|
||||
"""Return `True` if this is the xdist master, `False` otherwise
|
||||
def is_xdist_controller(request_or_session) -> bool:
|
||||
"""Return `True` if this is the xdist controller, `False` otherwise
|
||||
|
||||
Note: this method also returns `False` when distribution has not been
|
||||
activated at all.
|
||||
@@ -241,9 +246,13 @@ def is_xdist_master(request_or_session) -> bool:
|
||||
)
|
||||
|
||||
|
||||
# ALIAS: TODO, deprecate (#592)
|
||||
is_xdist_master = is_xdist_controller
|
||||
|
||||
|
||||
def get_xdist_worker_id(request_or_session) -> str:
|
||||
"""Return the id of the current worker ('gw0', 'gw1', etc) or 'master'
|
||||
if running on the 'master' node.
|
||||
if running on the controller node.
|
||||
|
||||
If not distributing tests (for example passing `-n0` or not passing `-n` at all)
|
||||
also return 'master'.
|
||||
@@ -253,6 +262,7 @@ def get_xdist_worker_id(request_or_session) -> str:
|
||||
if hasattr(request_or_session.config, "workerinput"):
|
||||
return request_or_session.config.workerinput["workerid"]
|
||||
else:
|
||||
# TODO: remove "master", ideally for a None
|
||||
return "master"
|
||||
|
||||
|
||||
@@ -261,6 +271,7 @@ def worker_id(request):
|
||||
"""Return the id of the current worker ('gw0', 'gw1', etc) or 'master'
|
||||
if running on the master node.
|
||||
"""
|
||||
# TODO: remove "master", ideally for a None
|
||||
return get_xdist_worker_id(request)
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,21 @@ from execnet.gateway_base import dumps, DumpError
|
||||
|
||||
from _pytest.config import _prepareconfig, Config
|
||||
|
||||
try:
|
||||
from setproctitle import setproctitle
|
||||
except ImportError:
|
||||
|
||||
def setproctitle(title):
|
||||
pass
|
||||
|
||||
|
||||
def worker_title(title):
|
||||
try:
|
||||
setproctitle(title)
|
||||
except Exception:
|
||||
# changing the process name is very optional, no errors please
|
||||
pass
|
||||
|
||||
|
||||
class WorkerInteractor:
|
||||
def __init__(self, config, channel):
|
||||
@@ -85,17 +100,27 @@ class WorkerInteractor:
|
||||
else:
|
||||
nextitem = None
|
||||
|
||||
worker_title("[pytest-xdist running] %s" % item.nodeid)
|
||||
|
||||
start = time.time()
|
||||
self.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
|
||||
duration = time.time() - start
|
||||
|
||||
worker_title("[pytest-xdist idle]")
|
||||
|
||||
self.sendevent(
|
||||
"runtest_protocol_complete", item_index=self.item_index, duration=duration
|
||||
)
|
||||
|
||||
def pytest_collection_finish(self, session):
|
||||
try:
|
||||
topdir = str(self.config.rootpath)
|
||||
except AttributeError: # pytest <= 6.1.0
|
||||
topdir = str(self.config.rootdir)
|
||||
|
||||
self.sendevent(
|
||||
"collectionfinish",
|
||||
topdir=str(session.fspath),
|
||||
topdir=topdir,
|
||||
ids=[item.nodeid for item in session.items],
|
||||
)
|
||||
|
||||
@@ -116,7 +141,7 @@ class WorkerInteractor:
|
||||
self.sendevent("testreport", data=data)
|
||||
|
||||
def pytest_collectreport(self, report):
|
||||
# send only reports that have not passed to master as optimization (#330)
|
||||
# send only reports that have not passed to controller as optimization (#330)
|
||||
if not report.passed:
|
||||
data = self.config.hook.pytest_report_to_serializable(
|
||||
config=self.config, report=report
|
||||
@@ -139,7 +164,7 @@ def serialize_warning_message(warning_message):
|
||||
message_class_name = type(warning_message.message).__name__
|
||||
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
|
||||
# if not, we will just use the exception message on the controller node
|
||||
try:
|
||||
dumps(warning_message.message.args)
|
||||
except DumpError:
|
||||
@@ -214,12 +239,14 @@ if __name__ == "__channelexec__":
|
||||
channel = channel # noqa
|
||||
workerinput, args, option_dict, change_sys_path = channel.receive()
|
||||
|
||||
if change_sys_path:
|
||||
if change_sys_path is None:
|
||||
importpath = os.getcwd()
|
||||
sys.path.insert(0, importpath)
|
||||
os.environ["PYTHONPATH"] = (
|
||||
importpath + os.pathsep + os.environ.get("PYTHONPATH", "")
|
||||
)
|
||||
else:
|
||||
sys.path = change_sys_path
|
||||
|
||||
os.environ["PYTEST_XDIST_TESTRUNUID"] = workerinput["testrunuid"]
|
||||
os.environ["PYTEST_XDIST_WORKER"] = workerinput["workerid"]
|
||||
|
||||
@@ -16,5 +16,5 @@ def report_collection_diff(from_collection, to_collection, from_id, to_id):
|
||||
"The difference is:\n"
|
||||
"{diff}"
|
||||
).format(from_id=from_id, to_id=to_id, diff="\n".join(diff))
|
||||
msg = "\n".join([x.rstrip() for x in error_message.split("\n")])
|
||||
msg = "\n".join(x.rstrip() for x in error_message.split("\n"))
|
||||
return msg
|
||||
|
||||
@@ -101,6 +101,14 @@ class EachScheduling:
|
||||
def mark_test_complete(self, node, item_index, duration=0):
|
||||
self.node2pending[node].remove(item_index)
|
||||
|
||||
def mark_test_pending(self, item):
|
||||
self.pending.insert(
|
||||
0,
|
||||
self.collection.index(item),
|
||||
)
|
||||
for node in self.node2pending:
|
||||
self.check_schedule(node)
|
||||
|
||||
def remove_node(self, node):
|
||||
# KeyError if we didn't get an add_node() yet
|
||||
pending = self.node2pending.pop(node)
|
||||
|
||||
@@ -151,6 +151,14 @@ class LoadScheduling:
|
||||
self.node2pending[node].remove(item_index)
|
||||
self.check_schedule(node, duration=duration)
|
||||
|
||||
def mark_test_pending(self, item):
|
||||
self.pending.insert(
|
||||
0,
|
||||
self.collection.index(item),
|
||||
)
|
||||
for node in self.node2pending:
|
||||
self.check_schedule(node)
|
||||
|
||||
def check_schedule(self, node, duration=0):
|
||||
"""Maybe schedule new items on the node
|
||||
|
||||
|
||||
@@ -243,6 +243,9 @@ class LoadScopeScheduling:
|
||||
self.assigned_work[node][scope][nodeid] = True
|
||||
self._reschedule(node)
|
||||
|
||||
def mark_test_pending(self, item):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _assign_work_unit(self, node):
|
||||
"""Assign a work unit to a node."""
|
||||
assert self.workqueue
|
||||
|
||||
@@ -9,6 +9,7 @@ import pytest
|
||||
import execnet
|
||||
|
||||
import xdist.remote
|
||||
from xdist.plugin import _sys_path
|
||||
|
||||
|
||||
def parse_spec_config(config):
|
||||
@@ -157,8 +158,7 @@ class NodeManager:
|
||||
|
||||
|
||||
class HostRSync(execnet.RSync):
|
||||
""" RSyncer that filters out common files
|
||||
"""
|
||||
"""RSyncer that filters out common files"""
|
||||
|
||||
def __init__(self, sourcedir, *args, **kwargs):
|
||||
self._synced = {}
|
||||
@@ -262,7 +262,8 @@ class WorkerController:
|
||||
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
|
||||
# restore sys.path from a frozen copy for local workers
|
||||
change_sys_path = _sys_path if self.gateway.spec.popen else None
|
||||
self.channel.send((self.workerinput, args, option_dict, change_sys_path))
|
||||
|
||||
if self.putevent:
|
||||
@@ -294,7 +295,7 @@ class WorkerController:
|
||||
self._shutdown_sent = True
|
||||
|
||||
def sendcommand(self, name, **kwargs):
|
||||
""" send a named parametrized command to the other side. """
|
||||
"""send a named parametrized command to the other side."""
|
||||
self.log("sending command {}(**{})".format(name, kwargs))
|
||||
self.channel.send((name, kwargs))
|
||||
|
||||
@@ -303,12 +304,12 @@ class WorkerController:
|
||||
self.putevent((eventname, kwargs))
|
||||
|
||||
def process_from_remote(self, eventcall): # noqa too complex
|
||||
""" this gets called for each object we receive from
|
||||
the other side and if the channel closes.
|
||||
"""this gets called for each object we receive from
|
||||
the other side and if the channel closes.
|
||||
|
||||
Note that channel callbacks run in the receiver
|
||||
thread of execnet gateways - we need to
|
||||
avoid raising exceptions or doing heavy work.
|
||||
Note that channel callbacks run in the receiver
|
||||
thread of execnet gateways - we need to
|
||||
avoid raising exceptions or doing heavy work.
|
||||
"""
|
||||
try:
|
||||
if eventcall == self.ENDMARK:
|
||||
|
||||
@@ -244,7 +244,7 @@ class TestDistribution:
|
||||
def test_data_exchange(self, testdir):
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
# This hook only called on master.
|
||||
# This hook only called on the controlling process.
|
||||
def pytest_configure_node(node):
|
||||
node.workerinput['a'] = 42
|
||||
node.workerinput['b'] = 7
|
||||
@@ -257,7 +257,7 @@ class TestDistribution:
|
||||
r = a + b
|
||||
config.workeroutput['r'] = r
|
||||
|
||||
# This hook only called on master.
|
||||
# This hook only called on the controlling process.
|
||||
def pytest_testnodedown(node, error):
|
||||
node.config.calc_result = node.workeroutput['r']
|
||||
|
||||
@@ -289,7 +289,7 @@ class TestDistribution:
|
||||
# on the worker
|
||||
if hasattr(session.config, 'workeroutput'):
|
||||
session.config.workeroutput['s2'] = 42
|
||||
# on the master
|
||||
# on the controller
|
||||
def pytest_testnodedown(node, error):
|
||||
assert node.workeroutput['s2'] == 42
|
||||
print ("s2call-finished")
|
||||
@@ -503,7 +503,7 @@ def test_session_hooks(testdir):
|
||||
if hasattr(session.config, 'workerinput'):
|
||||
name = "worker"
|
||||
else:
|
||||
name = "master"
|
||||
name = "controller"
|
||||
with open(name, "w") as f:
|
||||
f.write("xy")
|
||||
# let's fail on the worker
|
||||
@@ -524,12 +524,12 @@ def test_session_hooks(testdir):
|
||||
d = result.parseoutcomes()
|
||||
assert d["passed"] == 1
|
||||
assert testdir.tmpdir.join("worker").check()
|
||||
assert testdir.tmpdir.join("master").check()
|
||||
assert testdir.tmpdir.join("controller").check()
|
||||
|
||||
|
||||
def test_session_testscollected(testdir):
|
||||
"""
|
||||
Make sure master node is updating the session object with the number
|
||||
Make sure controller node is updating the session object with the number
|
||||
of tests collected from the workers.
|
||||
"""
|
||||
testdir.makepyfile(
|
||||
@@ -568,13 +568,13 @@ def test_fixture_teardown_failure(testdir):
|
||||
pass
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest_subprocess("--debug", p) # , "-n1")
|
||||
result = testdir.runpytest_subprocess(p, "-n1")
|
||||
result.stdout.fnmatch_lines(["*ValueError*42*", "*1 passed*1 error*"])
|
||||
assert result.ret
|
||||
|
||||
|
||||
def test_config_initialization(testdir, monkeypatch, pytestconfig):
|
||||
"""Ensure workers and master are initialized consistently. Integration test for #445"""
|
||||
"""Ensure workers and controller are initialized consistently. Integration test for #445"""
|
||||
testdir.makepyfile(
|
||||
**{
|
||||
"dir_a/test_foo.py": """
|
||||
@@ -718,8 +718,7 @@ def test_issue_594_random_parametrize(testdir):
|
||||
|
||||
|
||||
def test_tmpdir_disabled(testdir):
|
||||
"""Test xdist doesn't break if internal tmpdir plugin is disabled (#22).
|
||||
"""
|
||||
"""Test xdist doesn't break if internal tmpdir plugin is disabled (#22)."""
|
||||
p1 = testdir.makepyfile(
|
||||
"""
|
||||
def test_ok():
|
||||
@@ -733,8 +732,7 @@ def test_tmpdir_disabled(testdir):
|
||||
|
||||
@pytest.mark.parametrize("plugin", ["xdist.looponfail", "xdist.boxed"])
|
||||
def test_sub_plugins_disabled(testdir, plugin):
|
||||
"""Test that xdist doesn't break if we disable any of its sub-plugins. (#32)
|
||||
"""
|
||||
"""Test that xdist doesn't break if we disable any of its sub-plugins. (#32)"""
|
||||
p1 = testdir.makepyfile(
|
||||
"""
|
||||
def test_ok():
|
||||
@@ -1138,7 +1136,7 @@ def test_internal_error_with_maxfail(testdir):
|
||||
assert "INTERNALERROR" not in result.stderr.str()
|
||||
|
||||
|
||||
def test_internal_errors_propagate_to_master(testdir):
|
||||
def test_internal_errors_propagate_to_controller(testdir):
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
def pytest_collection_modifyitems():
|
||||
@@ -1239,14 +1237,22 @@ class TestFileScope:
|
||||
"test_b.py::TestB", result.outlines
|
||||
)
|
||||
|
||||
assert test_a_workers_and_test_count in (
|
||||
{"gw0": 10},
|
||||
{"gw1": 0},
|
||||
) or test_a_workers_and_test_count in ({"gw0": 0}, {"gw1": 10})
|
||||
assert test_b_workers_and_test_count in (
|
||||
{"gw0": 10},
|
||||
{"gw1": 0},
|
||||
) or test_b_workers_and_test_count in ({"gw0": 0}, {"gw1": 10})
|
||||
assert (
|
||||
test_a_workers_and_test_count
|
||||
in (
|
||||
{"gw0": 10},
|
||||
{"gw1": 0},
|
||||
)
|
||||
or test_a_workers_and_test_count in ({"gw0": 0}, {"gw1": 10})
|
||||
)
|
||||
assert (
|
||||
test_b_workers_and_test_count
|
||||
in (
|
||||
{"gw0": 10},
|
||||
{"gw1": 0},
|
||||
)
|
||||
or test_b_workers_and_test_count in ({"gw0": 0}, {"gw1": 10})
|
||||
)
|
||||
|
||||
def test_by_class(self, testdir):
|
||||
testdir.makepyfile(
|
||||
@@ -1271,14 +1277,22 @@ class TestFileScope:
|
||||
"test_a.py::TestB", result.outlines
|
||||
)
|
||||
|
||||
assert test_a_workers_and_test_count in (
|
||||
{"gw0": 10},
|
||||
{"gw1": 0},
|
||||
) or test_a_workers_and_test_count in ({"gw0": 0}, {"gw1": 10})
|
||||
assert test_b_workers_and_test_count in (
|
||||
{"gw0": 10},
|
||||
{"gw1": 0},
|
||||
) or test_b_workers_and_test_count in ({"gw0": 0}, {"gw1": 10})
|
||||
assert (
|
||||
test_a_workers_and_test_count
|
||||
in (
|
||||
{"gw0": 10},
|
||||
{"gw1": 0},
|
||||
)
|
||||
or test_a_workers_and_test_count in ({"gw0": 0}, {"gw1": 10})
|
||||
)
|
||||
assert (
|
||||
test_b_workers_and_test_count
|
||||
in (
|
||||
{"gw0": 10},
|
||||
{"gw1": 0},
|
||||
)
|
||||
or test_b_workers_and_test_count in ({"gw0": 0}, {"gw1": 10})
|
||||
)
|
||||
|
||||
def test_module_single_start(self, testdir):
|
||||
"""Fix test suite never finishing in case all workers start with a single test (#277)."""
|
||||
@@ -1408,12 +1422,18 @@ class TestAPI:
|
||||
del fake_request.config.workerinput
|
||||
assert not xdist.is_xdist_worker(fake_request)
|
||||
|
||||
def test_is_xdist_master(self, fake_request):
|
||||
def test_is_xdist_controller(self, fake_request):
|
||||
|
||||
assert not xdist.is_xdist_master(fake_request)
|
||||
assert not xdist.is_xdist_controller(fake_request)
|
||||
|
||||
del fake_request.config.workerinput
|
||||
assert xdist.is_xdist_master(fake_request)
|
||||
assert xdist.is_xdist_controller(fake_request)
|
||||
|
||||
fake_request.config.option.dist = "no"
|
||||
assert not xdist.is_xdist_master(fake_request)
|
||||
assert not xdist.is_xdist_controller(fake_request)
|
||||
|
||||
def test_get_xdist_worker_id(self, fake_request):
|
||||
assert xdist.get_xdist_worker_id(fake_request) == "gw5"
|
||||
|
||||
@@ -46,8 +46,7 @@ class TestHooks:
|
||||
)
|
||||
|
||||
def test_node_collection_finished(self, testdir):
|
||||
"""Test pytest_xdist_node_collection_finished hook (#8).
|
||||
"""
|
||||
"""Test pytest_xdist_node_collection_finished hook (#8)."""
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
def pytest_xdist_node_collection_finished(node, ids):
|
||||
@@ -61,3 +60,37 @@ class TestHooks:
|
||||
["*HOOK: gw0 test_a, test_b, test_c", "*HOOK: gw1 test_a, test_b, test_c"]
|
||||
)
|
||||
res.stdout.fnmatch_lines(["*3 passed*"])
|
||||
|
||||
|
||||
class TestCrashItem:
|
||||
@pytest.fixture(autouse=True)
|
||||
def create_test_file(self, testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
import os
|
||||
def test_a(): pass
|
||||
def test_b(): os._exit(1)
|
||||
def test_c(): pass
|
||||
def test_d(): pass
|
||||
"""
|
||||
)
|
||||
|
||||
def test_handlecrashitem(self, testdir):
|
||||
"""Test pytest_handlecrashitem hook."""
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
test_runs = 0
|
||||
|
||||
def pytest_handlecrashitem(crashitem, report, sched):
|
||||
global test_runs
|
||||
|
||||
if test_runs == 0:
|
||||
sched.mark_test_pending(crashitem)
|
||||
test_runs = 1
|
||||
else:
|
||||
print("HOOK: pytest_handlecrashitem")
|
||||
"""
|
||||
)
|
||||
res = testdir.runpytest("-n2", "-s")
|
||||
res.stdout.fnmatch_lines_random(["*HOOK: pytest_handlecrashitem"])
|
||||
res.stdout.fnmatch_lines(["*3 passed*"])
|
||||
|
||||
@@ -69,6 +69,12 @@ def test_auto_detect_cpus(testdir, monkeypatch):
|
||||
assert config.getoption("numprocesses") == 0
|
||||
assert config.getoption("dist") == "no"
|
||||
|
||||
config = testdir.parseconfigure("-nlogical", "--pdb")
|
||||
check_options(config)
|
||||
assert config.getoption("usepdb")
|
||||
assert config.getoption("numprocesses") == 0
|
||||
assert config.getoption("dist") == "no"
|
||||
|
||||
monkeypatch.delattr(os, "sched_getaffinity", raising=False)
|
||||
monkeypatch.setenv("TRAVIS", "true")
|
||||
config = testdir.parseconfigure("-nauto")
|
||||
@@ -81,12 +87,16 @@ def test_auto_detect_cpus_psutil(testdir, monkeypatch):
|
||||
|
||||
psutil = pytest.importorskip("psutil")
|
||||
|
||||
monkeypatch.setattr(psutil, "cpu_count", lambda logical=True: 42)
|
||||
monkeypatch.setattr(psutil, "cpu_count", lambda logical=True: 84 if logical else 42)
|
||||
|
||||
config = testdir.parseconfigure("-nauto")
|
||||
check_options(config)
|
||||
assert config.getoption("numprocesses") == 42
|
||||
|
||||
config = testdir.parseconfigure("-nlogical")
|
||||
check_options(config)
|
||||
assert config.getoption("numprocesses") == 84
|
||||
|
||||
|
||||
def test_hook_auto_num_workers(testdir, monkeypatch):
|
||||
from xdist.plugin import pytest_cmdline_main as check_options
|
||||
@@ -101,6 +111,10 @@ def test_hook_auto_num_workers(testdir, monkeypatch):
|
||||
check_options(config)
|
||||
assert config.getoption("numprocesses") == 42
|
||||
|
||||
config = testdir.parseconfigure("-nlogical")
|
||||
check_options(config)
|
||||
assert config.getoption("numprocesses") == 42
|
||||
|
||||
|
||||
def test_boxed_with_collect_only(testdir):
|
||||
from xdist.plugin import pytest_cmdline_main as check_options
|
||||
|
||||
@@ -37,7 +37,9 @@ class WorkerSetup:
|
||||
self.testdir = testdir
|
||||
self.events = Queue()
|
||||
|
||||
def setup(self,):
|
||||
def setup(
|
||||
self,
|
||||
):
|
||||
self.testdir.chdir()
|
||||
# import os ; os.environ['EXECNET_DEBUG'] = "2"
|
||||
self.gateway = execnet.makegateway()
|
||||
@@ -290,3 +292,17 @@ def test_remote_usage_prog(testdir, request):
|
||||
result = testdir.runpytest_subprocess("-n1")
|
||||
assert result.ret == 1
|
||||
result.stdout.fnmatch_lines(["*usage: *", "*error: my_usage_error"])
|
||||
|
||||
|
||||
def test_remote_sys_path(testdir):
|
||||
"""Work around sys.path differences due to execnet using `python -c`."""
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
import sys
|
||||
|
||||
def test_sys_path():
|
||||
assert "" not in sys.path
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("-n1")
|
||||
assert result.ret == 0
|
||||
|
||||
25
tox.ini
25
tox.ini
@@ -1,15 +1,16 @@
|
||||
[tox]
|
||||
envlist=
|
||||
linting
|
||||
py{35,36,37,38,39}-pytestlatest
|
||||
py38-pytestmaster
|
||||
py{36,37,38,39,310}-pytestlatest
|
||||
py38-pytestmain
|
||||
py38-psutil
|
||||
py38-setproctitle
|
||||
|
||||
[testenv]
|
||||
extras = testing
|
||||
deps =
|
||||
pytestlatest: pytest
|
||||
pytestmaster: git+https://github.com/pytest-dev/pytest.git@master
|
||||
pytestmain: git+https://github.com/pytest-dev/pytest.git
|
||||
commands=
|
||||
pytest {posargs}
|
||||
|
||||
@@ -21,13 +22,13 @@ deps = pytest
|
||||
commands =
|
||||
pytest {posargs:-k psutil}
|
||||
|
||||
[testenv:linting]
|
||||
skip_install = True
|
||||
usedevelop = True
|
||||
passenv = PRE_COMMIT_HOME
|
||||
deps =
|
||||
pre-commit
|
||||
commands = pre-commit run --all-files --show-diff-on-failure
|
||||
[testenv:py38-setproctitle]
|
||||
extras =
|
||||
testing
|
||||
setproctitle
|
||||
deps = pytest
|
||||
commands =
|
||||
pytest {posargs}
|
||||
|
||||
[testenv:release]
|
||||
changedir=
|
||||
@@ -42,7 +43,9 @@ commands =
|
||||
towncrier --version {posargs} --yes
|
||||
|
||||
[pytest]
|
||||
addopts = -ra
|
||||
# pytest-services also defines a worker_id fixture, disable
|
||||
# it so they don't conflict with each other (#611).
|
||||
addopts = -ra -p no:pytest-services
|
||||
testpaths = testing
|
||||
|
||||
[flake8]
|
||||
|
||||
Reference in New Issue
Block a user