Skip to content

Allow bucketing of test items by their direct parent or grand-parent #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 25, 2018
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
11 changes: 10 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Design

pytest-random-order plugin groups tests in buckets, shuffles them within buckets and then shuffles the buckets.

You can choose from four types of buckets:
You can choose from a few types of buckets:

class
Tests will be shuffled within a class and classes will be shuffled,
Expand All @@ -64,12 +64,21 @@ package
belong to package ``x.y.z`` do not belong to package ``x.y``, so they will fall in different buckets
when randomising with ``package`` bucket type.

parent
If you are using custom test items which don't belong to any module, you can use this to
limit reordering of test items to within the ``parent`` to which they belong. For normal test
functions the parent is the module in which they are declared.

grandparent
Similar to *parent* above, but use the parent of the parent of the test item as the bucket key instead.

global
All tests fall in the same bucket, full randomness, tests probably take longer to run.

none
Disable shuffling.


If you have three buckets of tests ``A``, ``B``, and ``C`` with three tests ``1`` and ``2``, and ``3`` in each of them,
then one of many potential orderings that non-global randomisation can produce could be:

Expand Down
4 changes: 3 additions & 1 deletion pytest_random_order/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def pytest_addoption(parser):
action='store',
dest='random_order_bucket',
default='module',
choices=('global', 'package', 'module', 'class', 'none'),
choices=('global', 'package', 'module', 'class', 'parent', 'grandparent', 'none'),
help='Limit reordering of test items across units of code',
)
group.addoption(
Expand Down Expand Up @@ -72,4 +72,6 @@ def pytest_collection_modifyitems(session, config, items):
'package': lambda x: x.module.__package__,
'module': lambda x: x.module.__name__,
'class': lambda x: (x.module.__name__, x.cls.__name__) if x.cls else x.module.__name__,
'parent': lambda x: x.parent,
'grandparent': lambda x: x.parent.parent,
}
2 changes: 1 addition & 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.6.0',
version='0.7.0',
author='Jazeps Basko',
author_email='jazeps.basko@gmail.com',
maintainer='Jazeps Basko',
Expand Down
2 changes: 2 additions & 0 deletions tests/test_actual_test_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def inspect_attr(this_call, prev_call, attr_name):
('package', 2, 5),
('global', 2, 5),
('none', 1, 1),
('parent', 1, 5),
('grandparent', 1, 5),
])
def test_it_works_with_actual_tests(tmp_tree_of_tests, get_test_calls, bucket, min_sequences, max_sequences):
sequences = set()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def test_help_message(testdir):
)
result.stdout.fnmatch_lines([
'random-order:',
'*--random-order-bucket={global,package,module,class,none}*',
'*--random-order-bucket={global,package,module,class,parent,grandparent,none}*',
'*--random-order-seed=*',
])

Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ deps =
pytest
pytest-xdist
ordereddict
pytest-xdist

[testenv:flake8]
skip_install = true
Expand Down