Skip to content

Commit be48a7c

Browse files
authored
Merge pull request #16 from eLRuLL/py26
adding python2.6 support
2 parents 28ef1bb + db09757 commit be48a7c

File tree

9 files changed

+28
-17
lines changed

9 files changed

+28
-17
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
sudo: false
44
language: python
55
python:
6+
- "2.6"
67
- "2.7"
78
- "3.5"
89

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pytest-random-order
22
===================================
33

4-
.. image:: https://img.shields.io/badge/python-2.7%2C%203.5-blue.svg
4+
.. image:: https://img.shields.io/badge/python-2.6%2C%202.7%2C%203.5-blue.svg
55
:target: https://github.com/jbasko/pytest-random-order
66

77
.. image:: https://img.shields.io/badge/coverage-98%25-green.svg

pytest_random_order/plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ def pytest_report_header(config):
3939

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

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

4747
return out
4848

@@ -60,7 +60,7 @@ def pytest_collection_modifyitems(session, config, items):
6060
except Exception as e:
6161
# See the finally block -- we only fail if we have lost user's tests.
6262
_, _, exc_tb = sys.exc_info()
63-
failure = 'pytest-random-order plugin has failed with {!r}:\n{}'.format(
63+
failure = 'pytest-random-order plugin has failed with {0!r}:\n{1}'.format(
6464
e, ''.join(traceback.format_tb(exc_tb, 10))
6565
)
6666
config.warn(0, failure, None)

pytest_random_order/shuffler.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# -*- coding: utf-8 -*-
22

3-
import collections
3+
from collections import namedtuple
4+
try:
5+
from collections import OrderedDict
6+
except ImportError:
7+
from ordereddict import OrderedDict
48
import random
59

610

@@ -15,7 +19,7 @@
1519
to preserve a distinct disabled sub-bucket within a larger bucket and not mix it up with another
1620
disabled sub-bucket of the same larger bucket.
1721
"""
18-
ItemKey = collections.namedtuple('ItemKey', field_names=('bucket', 'disabled', 'x'))
22+
ItemKey = namedtuple('ItemKey', field_names=('bucket', 'disabled', 'x'))
1923
ItemKey.__new__.__defaults__ = (None, None)
2024

2125

@@ -57,7 +61,7 @@ def get_full_bucket_key(item):
5761
# For a sequence of items A1, A2, B1, B2, C1, C2,
5862
# where key(A1) == key(A2) == key(C1) == key(C2),
5963
# items A1, A2, C1, and C2 will end up in the same bucket.
60-
buckets = collections.OrderedDict()
64+
buckets = OrderedDict()
6165
for item in items:
6266
full_bucket_key = get_full_bucket_key(item)
6367
if full_bucket_key not in buckets:

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def read(fname):
3131
'Topic :: Software Development :: Testing',
3232
'Programming Language :: Python',
3333
'Programming Language :: Python :: 2',
34+
'Programming Language :: Python :: 2.6',
3435
'Programming Language :: Python :: 2.7',
3536
'Programming Language :: Python :: 3',
3637
'Programming Language :: Python :: 3.5',

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ def get_test_calls():
3737
def twenty_tests():
3838
code = []
3939
for i in range(20):
40-
code.append('def test_a{}(): assert True\n'.format(str(i).zfill(2)))
40+
code.append('def test_a{0}(): assert True\n'.format(str(i).zfill(2)))
4141
return ''.join(code)
4242

4343

4444
@pytest.fixture
4545
def twenty_cls_tests():
4646
code = []
4747
for i in range(20):
48-
code.append('\tdef test_b{}(self): self.assertTrue\n'.format(str(i).zfill(2)))
48+
code.append('\tdef test_b{0}(self): self.assertTrue\n'.format(str(i).zfill(2)))
4949
return ''.join(code)

tests/test_actual_test_runs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def test_it_works_with_actual_tests(tmp_tree_of_tests, get_test_calls, bucket):
141141
sequences = set()
142142

143143
for x in range(5):
144-
result = tmp_tree_of_tests.runpytest('--random-order-bucket={}'.format(bucket), '--verbose')
144+
result = tmp_tree_of_tests.runpytest('--random-order-bucket={0}'.format(bucket), '--verbose')
145145
result.assert_outcomes(passed=14, failed=3)
146146
seq = get_test_calls(result)
147147
check_call_sequence(seq, bucket=bucket)
@@ -159,17 +159,17 @@ def test_random_order_seed_is_respected(testdir, twenty_tests, get_test_calls):
159159
'3': None,
160160
}
161161
for seed in call_sequences.keys():
162-
result = testdir.runpytest('--random-order-seed={}'.format(seed))
162+
result = testdir.runpytest('--random-order-seed={0}'.format(seed))
163163

164164
result.stdout.fnmatch_lines([
165-
'*Using --random-order-seed={}*'.format(seed),
165+
'*Using --random-order-seed={0}*'.format(seed),
166166
])
167167

168168
result.assert_outcomes(passed=20)
169169
call_sequences[seed] = get_test_calls(result)
170170

171171
for seed in call_sequences.keys():
172-
result = testdir.runpytest('--random-order-seed={}'.format(seed))
172+
result = testdir.runpytest('--random-order-seed={0}'.format(seed))
173173
result.assert_outcomes(passed=20)
174174
assert call_sequences[seed] == get_test_calls(result)
175175

@@ -194,7 +194,7 @@ def test_generated_seed_is_reported_and_run_can_be_reproduced(testdir, twenty_te
194194
break
195195
assert seed
196196

197-
result2 = testdir.runpytest('-v', '--random-order-seed={}'.format(seed))
197+
result2 = testdir.runpytest('-v', '--random-order-seed={0}'.format(seed))
198198
result2.assert_outcomes(passed=20)
199199
calls2 = get_test_calls(result2)
200200
assert calls == calls2

tests/test_markers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
def test_marker_disables_random_order_in_module(testdir, twenty_tests, get_test_calls, disabled):
66
testdir.makepyfile(
77
'import pytest\n' +
8-
('pytestmark = pytest.mark.random_order(disabled={})\n'.format(disabled)) +
8+
('pytestmark = pytest.mark.random_order(disabled={0})\n'.format(disabled)) +
99
twenty_tests
1010
)
1111

@@ -26,7 +26,7 @@ def test_marker_disables_random_order_in_class(testdir, twenty_cls_tests, get_te
2626
'import pytest\n\n' +
2727
'from unittest import TestCase\n\n' +
2828
'class MyTest(TestCase):\n' +
29-
'\tpytestmark = pytest.mark.random_order(disabled={})\n'.format(disabled) +
29+
'\tpytestmark = pytest.mark.random_order(disabled={0})\n'.format(disabled) +
3030
twenty_cls_tests + '\n'
3131
)
3232

tox.ini

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# For more information about tox, see https://tox.readthedocs.io/en/latest/
22
[tox]
3-
envlist = py27,py35,flake8
3+
envlist = py26,py27,py3,flake8
44

55
[testenv]
66
deps = pytest
77
commands = py.test {posargs:tests}
88

9+
[testenv:py26]
10+
deps =
11+
pytest
12+
ordereddict
13+
914
[testenv:flake8]
1015
skip_install = true
1116
deps = flake8

0 commit comments

Comments
 (0)