Display actual test ids in `--collect-only`

This commit is contained in:
Anthony Sottile 2018-11-25 09:33:18 -08:00
parent 59f65230b5
commit e9b2475e29
6 changed files with 43 additions and 35 deletions

View File

@ -0,0 +1 @@
Display actual test ids in ``--collect-only``.

View File

@ -138,7 +138,7 @@ class Node(object):
return cls
def __repr__(self):
return "<%s %r>" % (self.__class__.__name__, getattr(self, "name", None))
return "<%s %s>" % (self.__class__.__name__, getattr(self, "name", None))
def warn(self, _code_or_warning=None, message=None, code=None):
"""Issue a warning for this item.

View File

@ -489,26 +489,34 @@ class TestFunction(object):
]
)
def test_function_equality(self, testdir, tmpdir):
@staticmethod
def make_function(testdir, **kwargs):
from _pytest.fixtures import FixtureManager
config = testdir.parseconfigure()
session = testdir.Session(config)
session._fixturemanager = FixtureManager(session)
return pytest.Function(config=config, parent=session, **kwargs)
def test_function_equality(self, testdir, tmpdir):
def func1():
pass
def func2():
pass
f1 = pytest.Function(
name="name", parent=session, config=config, args=(1,), callobj=func1
)
f1 = self.make_function(testdir, name="name", args=(1,), callobj=func1)
assert f1 == f1
f2 = pytest.Function(name="name", config=config, callobj=func2, parent=session)
f2 = self.make_function(testdir, name="name", callobj=func2)
assert f1 != f2
def test_repr_produces_actual_test_id(self, testdir):
f = self.make_function(
testdir, name=r"test[\xe5]", callobj=self.test_repr_produces_actual_test_id
)
assert repr(f) == r"<Function test[\xe5]>"
def test_issue197_parametrize_emptyset(self, testdir):
testdir.makepyfile(
"""

View File

@ -474,9 +474,9 @@ class TestMetafunc(object):
result = testdir.runpytest("--collect-only", SHOW_PYTEST_WARNINGS_ARG)
result.stdout.fnmatch_lines(
[
"<Module 'test_parametrize_ids_exception.py'>",
" <Function 'test_foo[a]'>",
" <Function 'test_foo[b]'>",
"<Module test_parametrize_ids_exception.py>",
" <Function test_foo[a]>",
" <Function test_foo[b]>",
"*test_parametrize_ids_exception.py:6: *parameter arg at position 0*",
"*test_parametrize_ids_exception.py:6: *parameter arg at position 1*",
]

View File

@ -950,10 +950,10 @@ def test_collect_init_tests(testdir):
[
"collected 2 items",
"<Package *",
" <Module '__init__.py'>",
" <Function 'test_init'>",
" <Module 'test_foo.py'>",
" <Function 'test_foo'>",
" <Module __init__.py>",
" <Function test_init>",
" <Module test_foo.py>",
" <Function test_foo>",
]
)
result = testdir.runpytest("./tests", "--collect-only")
@ -961,10 +961,10 @@ def test_collect_init_tests(testdir):
[
"collected 2 items",
"<Package *",
" <Module '__init__.py'>",
" <Function 'test_init'>",
" <Module 'test_foo.py'>",
" <Function 'test_foo'>",
" <Module __init__.py>",
" <Function test_init>",
" <Module test_foo.py>",
" <Function test_foo>",
]
)
# Ignores duplicates with "." and pkginit (#4310).
@ -972,11 +972,11 @@ def test_collect_init_tests(testdir):
result.stdout.fnmatch_lines(
[
"collected 2 items",
"<Package */tests'>",
" <Module '__init__.py'>",
" <Function 'test_init'>",
" <Module 'test_foo.py'>",
" <Function 'test_foo'>",
"<Package */tests>",
" <Module __init__.py>",
" <Function test_init>",
" <Module test_foo.py>",
" <Function test_foo>",
]
)
# Same as before, but different order.
@ -984,21 +984,21 @@ def test_collect_init_tests(testdir):
result.stdout.fnmatch_lines(
[
"collected 2 items",
"<Package */tests'>",
" <Module '__init__.py'>",
" <Function 'test_init'>",
" <Module 'test_foo.py'>",
" <Function 'test_foo'>",
"<Package */tests>",
" <Module __init__.py>",
" <Function test_init>",
" <Module test_foo.py>",
" <Function test_foo>",
]
)
result = testdir.runpytest("./tests/test_foo.py", "--collect-only")
result.stdout.fnmatch_lines(
["<Package */tests'>", " <Module 'test_foo.py'>", " <Function 'test_foo'>"]
["<Package */tests>", " <Module test_foo.py>", " <Function test_foo>"]
)
assert "test_init" not in result.stdout.str()
result = testdir.runpytest("./tests/__init__.py", "--collect-only")
result.stdout.fnmatch_lines(
["<Package */tests'>", " <Module '__init__.py'>", " <Function 'test_init'>"]
["<Package */tests>", " <Module __init__.py>", " <Function test_init>"]
)
assert "test_foo" not in result.stdout.str()

View File

@ -263,7 +263,7 @@ class TestCollectonly(object):
)
result = testdir.runpytest("--collect-only")
result.stdout.fnmatch_lines(
["<Module 'test_collectonly_basic.py'>", " <Function 'test_func'>"]
["<Module test_collectonly_basic.py>", " <Function test_func>"]
)
def test_collectonly_skipped_module(self, testdir):
@ -307,11 +307,10 @@ class TestCollectonly(object):
assert result.ret == 0
result.stdout.fnmatch_lines(
[
"*<Module '*.py'>",
"* <Function 'test_func1'*>",
"* <Class 'TestClass'>",
# "* <Instance '()'>",
"* <Function 'test_method'*>",
"*<Module *.py>",
"* <Function test_func1>",
"* <Class TestClass>",
"* <Function test_method>",
]
)