Skip to content

Commit 1dd4e33

Browse files
authored
Fixes xdist integration (#50)
* Fixes xdist solution as suggested by @matejsp * Updates build code
1 parent e8ff95f commit 1dd4e33

File tree

10 files changed

+115
-40
lines changed

10 files changed

+115
-40
lines changed

.github/workflows/build-package.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Build package
5+
6+
on:
7+
[push]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
python-version: ["3.7", "3.8", "3.9", "3.10"]
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install flake8 pytest
30+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
31+
pip install .
32+
33+
- name: Lint with flake8
34+
run: |
35+
# stop the build if there are Python syntax errors or undefined names
36+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
37+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
38+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
39+
40+
- name: Test with pytest
41+
run: |
42+
pytest

.github/workflows/publish-package.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
2+
3+
name: Publish package
4+
5+
on:
6+
release:
7+
types: [published]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
16+
- uses: actions/checkout@v3
17+
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: '3.x'
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install build
27+
28+
- name: Build package
29+
run: python -m build
30+
31+
- name: Publish a Python distribution to PyPI
32+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
33+
uses: pypa/gh-action-pypi-publish@release/v1
34+
with:
35+
user: __token__
36+
password: ${{ secrets.PYPI_API_TOKEN }}

.travis.yml

-18
This file was deleted.

README.rst

+6
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ from being registered so its hooks won't be registered and its command line opti
234234
Changelog
235235
--------------
236236

237+
v1.1.0 (2022-12-03)
238+
+++++++++++++++++++
239+
240+
* Fixes xdist support (thanks @matejsp)
241+
242+
237243
v1.0.4 (2018-11-30)
238244
+++++++++++++++++++
239245

random_order/plugin.py

+12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from random_order.cache import process_failed_first_last_failed
1010
from random_order.config import Config
1111
from random_order.shuffler import _disable, _get_set_of_item_ids, _shuffle_items
12+
from random_order.xdist import XdistHooks
1213

1314

1415
def pytest_addoption(parser):
@@ -42,6 +43,17 @@ def pytest_configure(config):
4243
'random_order(disabled=True): disable reordering of tests within a module or class'
4344
)
4445

46+
if config.pluginmanager.hasplugin('xdist'):
47+
config.pluginmanager.register(XdistHooks())
48+
49+
if hasattr(config, 'workerinput'):
50+
# pytest-xdist: use seed generated on main.
51+
seed = config.workerinput['random_order_seed']
52+
if hasattr(config, 'cache'):
53+
assert config.cache is not None
54+
config.cache.set('random_order_seed', seed)
55+
config.option.random_order_seed = seed
56+
4557

4658
def pytest_report_header(config):
4759
plugin = Config(config)

random_order/xdist.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import pytest
2+
3+
4+
class XdistHooks:
5+
6+
def pytest_configure_node(self, node: pytest.Item) -> None:
7+
seed = node.config.getoption('random_order_seed')
8+
node.workerinput['random_order_seed'] = seed

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ py
33
pytest
44
pytest-xdist
55
sphinx
6-
tox

setup.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def read(fname):
1414

1515
setup(
1616
name='pytest-random-order',
17-
version='1.0.4',
17+
version='1.1.0',
1818
author='Jazeps Basko',
1919
author_email='[email protected]',
2020
maintainer='Jazeps Basko',
@@ -40,6 +40,10 @@ def read(fname):
4040
'Programming Language :: Python :: 3',
4141
'Programming Language :: Python :: 3.5',
4242
'Programming Language :: Python :: 3.6',
43+
'Programming Language :: Python :: 3.7',
44+
'Programming Language :: Python :: 3.8',
45+
'Programming Language :: Python :: 3.9',
46+
'Programming Language :: Python :: 3.10',
4347
'License :: OSI Approved :: MIT License',
4448
],
4549
keywords='pytest random test order shuffle',

tests/test_xdist.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
def test_xdist_not_broken(testdir, twenty_tests):
3+
testdir.makepyfile(twenty_tests)
4+
5+
result = testdir.runpytest('--random-order', '-n', '5')
6+
result.assert_outcomes(passed=20)

tox.ini

-20
This file was deleted.

0 commit comments

Comments
 (0)