diff --git a/.gitignore b/.gitignore index 98378f5..f0e0eac 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ build/ dist/ .DS_Store +.idea/ +venv/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4cb43a7..0000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: python -sudo: false -python: - - "2.7" - - "3.3" - - "3.4" - - "3.5" - - "3.6" -install: - - "pip install -U flake8 pytest" - - "pip install -e ." -before_script: - - "flake8" -script: - - py.test diff --git a/LICENSE b/LICENSE index 781af49..eae3ade 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.rst b/README.rst index 5f40e58..3f95bf2 100644 --- a/README.rst +++ b/README.rst @@ -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. @@ -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 @@ -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. diff --git a/pytest_test_groups/__init__.py b/pytest_split_tests/__init__.py similarity index 85% rename from pytest_test_groups/__init__.py rename to pytest_split_tests/__init__.py index 258d130..fbb0491 100644 --- a/pytest_test_groups/__init__.py +++ b/pytest_split_tests/__init__.py @@ -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): @@ -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) @@ -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( diff --git a/setup.py b/setup.py index 3c305b3..a2618e1 100644 --- a/setup.py +++ b/setup.py @@ -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='mark@markadams.me', - 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='wchill@chilly.codes', + packages=['pytest_split_tests'], + version='1.0.4', long_description=read('README.rst'), install_requires=['pytest>=2.5'], classifiers=['Development Status :: 5 - Production/Stable', @@ -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', ] }, ) diff --git a/tests/test_groups.py b/tests/test_groups.py index f2b18df..8cb9383 100644 --- a/tests/test_groups.py +++ b/tests/test_groups.py @@ -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(): diff --git a/tests/test_pytest.py b/tests/test_pytest.py index 6dd4211..c7767e2 100644 --- a/tests/test_pytest.py +++ b/tests/test_pytest.py @@ -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 @@ -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) diff --git a/tox.ini b/tox.ini index a11fda8..6e0e358 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{27,33,34,35}, flake8 +envlist = py{27,35,36,37}, flake8 [testenv] commands =