Skip to content

Commit

Permalink
Pull changes by @craigds to run tests in original order
Browse files Browse the repository at this point in the history
  • Loading branch information
wchill committed Mar 22, 2019
1 parent 3cacc84 commit 459009b
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
build/
dist/
.DS_Store
.idea/
venv/
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019 Eric Ahn
Copyright (c) 2016 Mark Adams

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
16 changes: 6 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
.. image:: https://secure.travis-ci.org/mark-adams/pytest-test-groups.png?branch=master
:alt: Build Status
:target: https://travis-ci.org/mark-adams/pytest-test-groups

Welcome to pytest-test-groups!
Welcome to pytest-split-tests!
==============================

pytest-test-groups allows you to split your test runs into groups of a specific
pytest-split-tests allows you to split your test runs into groups of a specific
size to make it easier to split up your test runs.


Expand All @@ -14,13 +10,13 @@ Usage

::

# Install pytest-test-groups
pip install pytest-test-groups
# Install pytest-split-tests
pip install pytest-split-tests

# Split the tests into 10 groups and run the second group
py.test --test-group-count 10 --test-group=2
# Randomize the test order, split into 10 groups, and run the second group
# Assign tests pseudo-randomly into 10 groups, and run the second group
py.test --test-group-count 10 --test-group=2 --test-group-random-seed=12345


Expand All @@ -29,6 +25,6 @@ Why would I use this?

Sometimes you may have some long running test jobs that take a
while to complete. This can be a major headache when trying to
run tests quickly. pytest-test-groups allows you to easily say
run tests quickly. pytest-split-tests allows you to easily say
"split my tests into groups of 10 tests and run the second group".
This is primarily useful in the context of CI builds.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def pytest_addoption(parser):
group.addoption('--test-group', dest='test-group', type=int,
help='The group of tests that should be executed')
group.addoption('--test-group-random-seed', dest='random-seed', type=int,
help='Integer to seed pseudo-random test ordering')
help='Integer to seed pseudo-random test selection')


def pytest_collection_modifyitems(session, config, items):
Expand All @@ -42,7 +42,9 @@ def pytest_collection_modifyitems(session, config, items):
if not group_count or not group_id:
return

if seed:
original_order = {item: index for index, item in enumerate(items)}

if seed is not False:
seeded = Random(seed)
seeded.shuffle(items)

Expand All @@ -52,6 +54,10 @@ def pytest_collection_modifyitems(session, config, items):
tests_in_group = get_group(items, group_size, group_id)
items[:] = tests_in_group

if seed is not False:
# Revert the shuffled sample of tests back to their original order.
items.sort(key=original_order.__getitem__)

terminal_reporter = config.pluginmanager.get_plugin('terminalreporter')
terminal_writer = create_terminal_writer(config)
message = terminal_writer.markup(
Expand Down
23 changes: 12 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ def read(fname):


setup(
name="pytest-test-groups",
name="pytest-split-tests",
description=('A Pytest plugin for running a subset of your tests by '
'splitting them in to equally sized groups.'),
url='https://github.com/mark-adams/pytest-test-groups',
author='Mark Adams',
author_email='[email protected]',
packages=['pytest_test_groups'],
version='1.0.3',
'splitting them in to equally sized groups. Forked from '
'Mark Adams\' original project pytest-test-groups.'),
url='https://github.com/wchill/pytest-split-tests',
author='Eric Ahn',
author_email='[email protected]',
packages=['pytest_split_tests'],
version='1.0.4',
long_description=read('README.rst'),
install_requires=['pytest>=2.5'],
classifiers=['Development Status :: 5 - Production/Stable',
Expand All @@ -27,13 +28,13 @@ def read(fname):
'Programming Language :: Python',
'Topic :: Software Development :: Testing',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5'
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7'
],
entry_points={
'pytest11': [
'test-groups = pytest_test_groups',
'split-tests = pytest_split_tests',
]
},
)
2 changes: 1 addition & 1 deletion tests/test_groups.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from pytest_test_groups import get_group, get_group_size
from pytest_split_tests import get_group, get_group_size


def test_group_size_computed_correctly_for_even_group():
Expand Down
24 changes: 22 additions & 2 deletions tests/test_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def test_z(): pass


def test_group_runs_all_test(testdir):
"""Given a large set of tests executed in random order, assert that all
tests are executed.
"""Given a large set of tests executed with a random seed, assert that all
tests are executed exactly once.
"""
testdir.makepyfile("""
def test_b(): pass
Expand Down Expand Up @@ -71,3 +71,23 @@ def test_z(): pass
all_tests = [x.item.name for x in result.calls if x._name == 'pytest_runtest_call']

assert set(group_1 + group_2) == set(all_tests)


def test_random_group_runs_in_original_order(testdir):
"""When running tests with a random seed, check test order is unchanged"""
testdir.makepyfile("""
def test_i(): pass
def test_h(): pass
def test_g(): pass
def test_f(): pass
def test_e(): pass
def test_d(): pass
def test_c(): pass
def test_b(): pass
""")

result = testdir.inline_run('--test-group-count', '2',
'--test-group', '1',
'--test-group-random-seed', '5')
group_1 = [x.item.name for x in result.calls if x._name == 'pytest_runtest_call']
assert group_1 == sorted(group_1, reverse=True)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{27,33,34,35}, flake8
envlist = py{27,35,36,37}, flake8

[testenv]
commands =
Expand Down

0 comments on commit 459009b

Please sign in to comment.