Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/build-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Build package

on:
[push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install .

- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

- name: Test with pytest
run: |
pytest
36 changes: 36 additions & 0 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Publish package

on:
release:
types: [published]

jobs:
build:

runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build

- name: Build package
run: python -m build

- name: Publish a Python distribution to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ from being registered so its hooks won't be registered and its command line opti
Changelog
--------------

v1.1.0 (2022-12-03)
+++++++++++++++++++

* Fixes xdist support (thanks @matejsp)


v1.0.4 (2018-11-30)
+++++++++++++++++++

Expand Down
12 changes: 12 additions & 0 deletions random_order/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from random_order.cache import process_failed_first_last_failed
from random_order.config import Config
from random_order.shuffler import _disable, _get_set_of_item_ids, _shuffle_items
from random_order.xdist import XdistHooks


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

if config.pluginmanager.hasplugin('xdist'):
config.pluginmanager.register(XdistHooks())

if hasattr(config, 'workerinput'):
# pytest-xdist: use seed generated on main.
seed = config.workerinput['random_order_seed']
if hasattr(config, 'cache'):
assert config.cache is not None
config.cache.set('random_order_seed', seed)
config.option.random_order_seed = seed


def pytest_report_header(config):
plugin = Config(config)
Expand Down
8 changes: 8 additions & 0 deletions random_order/xdist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest


class XdistHooks:

def pytest_configure_node(self, node: pytest.Item) -> None:
seed = node.config.getoption('random_order_seed')
node.workerinput['random_order_seed'] = seed
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ py
pytest
pytest-xdist
sphinx
tox
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def read(fname):

setup(
name='pytest-random-order',
version='1.0.4',
version='1.1.0',
author='Jazeps Basko',
author_email='jazeps.basko@gmail.com',
maintainer='Jazeps Basko',
Expand All @@ -40,6 +40,10 @@ def read(fname):
'Programming Language :: Python :: 3',
'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',
'License :: OSI Approved :: MIT License',
],
keywords='pytest random test order shuffle',
Expand Down
6 changes: 6 additions & 0 deletions tests/test_xdist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

def test_xdist_not_broken(testdir, twenty_tests):
testdir.makepyfile(twenty_tests)

result = testdir.runpytest('--random-order', '-n', '5')
result.assert_outcomes(passed=20)
20 changes: 0 additions & 20 deletions tox.ini

This file was deleted.