Skip to content

Commit

Permalink
pytest-xdist (#25)
Browse files Browse the repository at this point in the history
Make it work with pytest-xdist as requested in #22 - generate random order seed during command line argument initialisation so that all processes get the same default value.
  • Loading branch information
jbasko authored Mar 19, 2018
1 parent 3e65538 commit 66cb677
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ python:
- "2.6"
- "2.7"
- "3.5"
- "3.6"

install:
- pip install tox
Expand Down
17 changes: 5 additions & 12 deletions pytest_random_order/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,23 @@ def pytest_addoption(parser):
'--random-order-seed',
action='store',
dest='random_order_seed',
default=None,
default=str(random.randint(1, 1000000)),
help='Seed for the test order randomiser to produce a random order that can be reproduced using this seed',
)


def pytest_configure(config):
config.addinivalue_line("markers", "random_order(disabled=True): disable reordering of tests within a module or class")

if config.getoption('random_order_seed'):
seed = str(config.getoption('random_order_seed'))
else:
seed = str(random.randint(1, 1000000))
config.random_order_seed = seed


def pytest_report_header(config):
out = ''

if config.getoption('random_order_bucket'):
bucket = config.getoption('random_order_bucket')
out += "Using --random-order-bucket={0}\n".format(bucket)
out += "Using --random-order-bucket={0}\n".format(config.getoption('random_order_bucket'))

if hasattr(config, 'random_order_seed'):
out += 'Using --random-order-seed={0}\n'.format(getattr(config, 'random_order_seed'))
if config.getoption('random_order_seed'):
out += 'Using --random-order-seed={0}\n'.format(config.getoption('random_order_seed'))

return out

Expand All @@ -53,7 +46,7 @@ def pytest_collection_modifyitems(session, config, items):
item_ids = _get_set_of_item_ids(items)

try:
seed = getattr(config, 'random_order_seed', None)
seed = str(config.getoption('random_order_seed'))
bucket_type = config.getoption('random_order_bucket')
if bucket_type != 'none':
_shuffle_items(items, bucket_key=_random_order_item_keys[bucket_type], disable=_disable, seed=seed)
Expand Down
7 changes: 3 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pytest
tox
coverage
py

pytest
pytest-xdist
sphinx

tox
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def read(fname):

setup(
name='pytest-random-order',
version='0.5.6',
version='0.6.0',
author='Jazeps Basko',
author_email='[email protected]',
maintainer='Jazeps Basko',
Expand All @@ -35,6 +35,7 @@ def read(fname):
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'License :: OSI Approved :: MIT License',
],
entry_points={
Expand Down
7 changes: 5 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
envlist = py26,py27,py3,flake8

[testenv]
deps = pytest
commands = py.test {posargs:tests}
deps =
pytest
pytest-xdist
commands = py.test -n 2 {posargs:tests}

[testenv:py26]
deps =
pytest
pytest-xdist
ordereddict

[testenv:flake8]
Expand Down

0 comments on commit 66cb677

Please sign in to comment.