1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
import collections
import pytest
pytest_plugins = "pytester"
Call = collections.namedtuple("Call", field_names=("package", "module", "cls", "name"))
def _get_test_calls(result):
"""
Returns a tuple of test calls in the order they were made.
"""
calls = []
for c in result.reprec.getcalls("pytest_runtest_call"):
calls.append(
Call(
package=c.item.module.__package__,
module=c.item.module.__name__,
cls=(c.item.module.__name__, c.item.cls.__name__) if c.item.cls else None,
name=c.item.name,
)
)
return tuple(calls)
@pytest.fixture
def get_test_calls():
"""
Returns a function to get runtest calls out from testdir.pytestrun result object.
"""
return _get_test_calls
@pytest.fixture
def twenty_tests():
code = []
for i in range(20):
code.append("def test_a{0}(): assert True\n".format(str(i).zfill(2)))
return "".join(code)
@pytest.fixture
def twenty_cls_tests():
code = []
for i in range(20):
code.append("\tdef test_b{0}(self): self.assertTrue\n".format(str(i).zfill(2)))
return "".join(code)
|