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 return cls
def __repr__(self): 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): def warn(self, _code_or_warning=None, message=None, code=None):
"""Issue a warning for this item. """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 from _pytest.fixtures import FixtureManager
config = testdir.parseconfigure() config = testdir.parseconfigure()
session = testdir.Session(config) session = testdir.Session(config)
session._fixturemanager = FixtureManager(session) session._fixturemanager = FixtureManager(session)
return pytest.Function(config=config, parent=session, **kwargs)
def test_function_equality(self, testdir, tmpdir):
def func1(): def func1():
pass pass
def func2(): def func2():
pass pass
f1 = pytest.Function( f1 = self.make_function(testdir, name="name", args=(1,), callobj=func1)
name="name", parent=session, config=config, args=(1,), callobj=func1
)
assert f1 == f1 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 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): def test_issue197_parametrize_emptyset(self, testdir):
testdir.makepyfile( testdir.makepyfile(
""" """

View File

@ -474,9 +474,9 @@ class TestMetafunc(object):
result = testdir.runpytest("--collect-only", SHOW_PYTEST_WARNINGS_ARG) result = testdir.runpytest("--collect-only", SHOW_PYTEST_WARNINGS_ARG)
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
[ [
"<Module 'test_parametrize_ids_exception.py'>", "<Module test_parametrize_ids_exception.py>",
" <Function 'test_foo[a]'>", " <Function test_foo[a]>",
" <Function 'test_foo[b]'>", " <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 0*",
"*test_parametrize_ids_exception.py:6: *parameter arg at position 1*", "*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", "collected 2 items",
"<Package *", "<Package *",
" <Module '__init__.py'>", " <Module __init__.py>",
" <Function 'test_init'>", " <Function test_init>",
" <Module 'test_foo.py'>", " <Module test_foo.py>",
" <Function 'test_foo'>", " <Function test_foo>",
] ]
) )
result = testdir.runpytest("./tests", "--collect-only") result = testdir.runpytest("./tests", "--collect-only")
@ -961,10 +961,10 @@ def test_collect_init_tests(testdir):
[ [
"collected 2 items", "collected 2 items",
"<Package *", "<Package *",
" <Module '__init__.py'>", " <Module __init__.py>",
" <Function 'test_init'>", " <Function test_init>",
" <Module 'test_foo.py'>", " <Module test_foo.py>",
" <Function 'test_foo'>", " <Function test_foo>",
] ]
) )
# Ignores duplicates with "." and pkginit (#4310). # Ignores duplicates with "." and pkginit (#4310).
@ -972,11 +972,11 @@ def test_collect_init_tests(testdir):
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
[ [
"collected 2 items", "collected 2 items",
"<Package */tests'>", "<Package */tests>",
" <Module '__init__.py'>", " <Module __init__.py>",
" <Function 'test_init'>", " <Function test_init>",
" <Module 'test_foo.py'>", " <Module test_foo.py>",
" <Function 'test_foo'>", " <Function test_foo>",
] ]
) )
# Same as before, but different order. # Same as before, but different order.
@ -984,21 +984,21 @@ def test_collect_init_tests(testdir):
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
[ [
"collected 2 items", "collected 2 items",
"<Package */tests'>", "<Package */tests>",
" <Module '__init__.py'>", " <Module __init__.py>",
" <Function 'test_init'>", " <Function test_init>",
" <Module 'test_foo.py'>", " <Module test_foo.py>",
" <Function 'test_foo'>", " <Function test_foo>",
] ]
) )
result = testdir.runpytest("./tests/test_foo.py", "--collect-only") result = testdir.runpytest("./tests/test_foo.py", "--collect-only")
result.stdout.fnmatch_lines( 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() assert "test_init" not in result.stdout.str()
result = testdir.runpytest("./tests/__init__.py", "--collect-only") result = testdir.runpytest("./tests/__init__.py", "--collect-only")
result.stdout.fnmatch_lines( 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() assert "test_foo" not in result.stdout.str()

View File

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