-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes randomisation of doctests (#37)
* Fixes issues with doctests reported in #36 - ``class``, ``package`` and ``module`` didn't work because ``DoctestItem`` doesn't have ``cls`` or ``module`` attributes. Thanks @tobywf. * Deprecates ``none`` bucket type. * With tox, run tests of pytest-random-order with both pytest 3 and 4.
- Loading branch information
Showing
6 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# -*- coding: utf-8 -*- | ||
import py | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def tmp_tree_of_tests(testdir): | ||
""" | ||
Creates a directory structure: | ||
tmpdir/ | ||
foo.py | ||
""" | ||
|
||
utils_package = testdir.mkpydir('utils') | ||
utils_package.join('__init__.py').write('') | ||
|
||
utils_package.join('foo.py').write(py.code.Source(''' | ||
def add(a, b): | ||
""" | ||
>>> add(1, 1) | ||
2 | ||
>>> add(0, 0) | ||
0 | ||
""" | ||
return a + b | ||
def subtract(a, b): | ||
""" | ||
>>> subtract(1, 1) | ||
0 | ||
>>> subtract(0, 2) | ||
-2 | ||
""" | ||
return a - b | ||
''')) | ||
|
||
return testdir | ||
|
||
|
||
@pytest.mark.parametrize('bucket', [ | ||
'global', | ||
'package', | ||
'module', | ||
'class', | ||
'parent', | ||
'grandparent', | ||
'none', | ||
]) | ||
def test_doctests(tmp_tree_of_tests, get_test_calls, bucket): | ||
result1 = tmp_tree_of_tests.runpytest( | ||
'--doctest-modules', '--random-order-bucket={0}'.format(bucket), '--verbose', '-s', | ||
) | ||
result1.assert_outcomes(passed=2, failed=0) | ||
assert 'PytestWarning' not in result1.stdout.str() | ||
assert 'PytestWarning' not in result1.stderr.str() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters