Skip to content

Commit 66cb677

Browse files
authored
pytest-xdist (#25)
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.
1 parent 3e65538 commit 66cb677

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ python:
66
- "2.6"
77
- "2.7"
88
- "3.5"
9+
- "3.6"
910

1011
install:
1112
- pip install tox

pytest_random_order/plugin.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,23 @@ def pytest_addoption(parser):
1919
'--random-order-seed',
2020
action='store',
2121
dest='random_order_seed',
22-
default=None,
22+
default=str(random.randint(1, 1000000)),
2323
help='Seed for the test order randomiser to produce a random order that can be reproduced using this seed',
2424
)
2525

2626

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

30-
if config.getoption('random_order_seed'):
31-
seed = str(config.getoption('random_order_seed'))
32-
else:
33-
seed = str(random.randint(1, 1000000))
34-
config.random_order_seed = seed
35-
3630

3731
def pytest_report_header(config):
3832
out = ''
3933

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

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

4740
return out
4841

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

5548
try:
56-
seed = getattr(config, 'random_order_seed', None)
49+
seed = str(config.getoption('random_order_seed'))
5750
bucket_type = config.getoption('random_order_bucket')
5851
if bucket_type != 'none':
5952
_shuffle_items(items, bucket_key=_random_order_item_keys[bucket_type], disable=_disable, seed=seed)

requirements.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
pytest
2-
tox
31
coverage
42
py
5-
3+
pytest
4+
pytest-xdist
65
sphinx
7-
6+
tox

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def read(fname):
1313

1414
setup(
1515
name='pytest-random-order',
16-
version='0.5.6',
16+
version='0.6.0',
1717
author='Jazeps Basko',
1818
author_email='jazeps.basko@gmail.com',
1919
maintainer='Jazeps Basko',
@@ -35,6 +35,7 @@ def read(fname):
3535
'Programming Language :: Python :: 2.7',
3636
'Programming Language :: Python :: 3',
3737
'Programming Language :: Python :: 3.5',
38+
'Programming Language :: Python :: 3.6',
3839
'License :: OSI Approved :: MIT License',
3940
],
4041
entry_points={

tox.ini

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
envlist = py26,py27,py3,flake8
44

55
[testenv]
6-
deps = pytest
7-
commands = py.test {posargs:tests}
6+
deps =
7+
pytest
8+
pytest-xdist
9+
commands = py.test -n 2 {posargs:tests}
810

911
[testenv:py26]
1012
deps =
1113
pytest
14+
pytest-xdist
1215
ordereddict
1316

1417
[testenv:flake8]

0 commit comments

Comments
 (0)