Skip to content

Commit e9b2475

Browse files
committed
Display actual test ids in --collect-only
1 parent 59f6523 commit e9b2475

File tree

6 files changed

+43
-35
lines changed

6 files changed

+43
-35
lines changed

changelog/4458.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Display actual test ids in ``--collect-only``.

src/_pytest/nodes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def _getcustomclass(self, name):
138138
return cls
139139

140140
def __repr__(self):
141-
return "<%s %r>" % (self.__class__.__name__, getattr(self, "name", None))
141+
return "<%s %s>" % (self.__class__.__name__, getattr(self, "name", None))
142142

143143
def warn(self, _code_or_warning=None, message=None, code=None):
144144
"""Issue a warning for this item.

testing/python/collect.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -489,26 +489,34 @@ def __call__(self, tmpdir):
489489
]
490490
)
491491

492-
def test_function_equality(self, testdir, tmpdir):
492+
@staticmethod
493+
def make_function(testdir, **kwargs):
493494
from _pytest.fixtures import FixtureManager
494495

495496
config = testdir.parseconfigure()
496497
session = testdir.Session(config)
497498
session._fixturemanager = FixtureManager(session)
498499

500+
return pytest.Function(config=config, parent=session, **kwargs)
501+
502+
def test_function_equality(self, testdir, tmpdir):
499503
def func1():
500504
pass
501505

502506
def func2():
503507
pass
504508

505-
f1 = pytest.Function(
506-
name="name", parent=session, config=config, args=(1,), callobj=func1
507-
)
509+
f1 = self.make_function(testdir, name="name", args=(1,), callobj=func1)
508510
assert f1 == f1
509-
f2 = pytest.Function(name="name", config=config, callobj=func2, parent=session)
511+
f2 = self.make_function(testdir, name="name", callobj=func2)
510512
assert f1 != f2
511513

514+
def test_repr_produces_actual_test_id(self, testdir):
515+
f = self.make_function(
516+
testdir, name=r"test[\xe5]", callobj=self.test_repr_produces_actual_test_id
517+
)
518+
assert repr(f) == r"<Function test[\xe5]>"
519+
512520
def test_issue197_parametrize_emptyset(self, testdir):
513521
testdir.makepyfile(
514522
"""

testing/python/metafunc.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,9 @@ def test_foo(arg):
474474
result = testdir.runpytest("--collect-only", SHOW_PYTEST_WARNINGS_ARG)
475475
result.stdout.fnmatch_lines(
476476
[
477-
"<Module 'test_parametrize_ids_exception.py'>",
478-
" <Function 'test_foo[a]'>",
479-
" <Function 'test_foo[b]'>",
477+
"<Module test_parametrize_ids_exception.py>",
478+
" <Function test_foo[a]>",
479+
" <Function test_foo[b]>",
480480
"*test_parametrize_ids_exception.py:6: *parameter arg at position 0*",
481481
"*test_parametrize_ids_exception.py:6: *parameter arg at position 1*",
482482
]

testing/test_collection.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -950,55 +950,55 @@ def test_collect_init_tests(testdir):
950950
[
951951
"collected 2 items",
952952
"<Package *",
953-
" <Module '__init__.py'>",
954-
" <Function 'test_init'>",
955-
" <Module 'test_foo.py'>",
956-
" <Function 'test_foo'>",
953+
" <Module __init__.py>",
954+
" <Function test_init>",
955+
" <Module test_foo.py>",
956+
" <Function test_foo>",
957957
]
958958
)
959959
result = testdir.runpytest("./tests", "--collect-only")
960960
result.stdout.fnmatch_lines(
961961
[
962962
"collected 2 items",
963963
"<Package *",
964-
" <Module '__init__.py'>",
965-
" <Function 'test_init'>",
966-
" <Module 'test_foo.py'>",
967-
" <Function 'test_foo'>",
964+
" <Module __init__.py>",
965+
" <Function test_init>",
966+
" <Module test_foo.py>",
967+
" <Function test_foo>",
968968
]
969969
)
970970
# Ignores duplicates with "." and pkginit (#4310).
971971
result = testdir.runpytest("./tests", ".", "--collect-only")
972972
result.stdout.fnmatch_lines(
973973
[
974974
"collected 2 items",
975-
"<Package */tests'>",
976-
" <Module '__init__.py'>",
977-
" <Function 'test_init'>",
978-
" <Module 'test_foo.py'>",
979-
" <Function 'test_foo'>",
975+
"<Package */tests>",
976+
" <Module __init__.py>",
977+
" <Function test_init>",
978+
" <Module test_foo.py>",
979+
" <Function test_foo>",
980980
]
981981
)
982982
# Same as before, but different order.
983983
result = testdir.runpytest(".", "tests", "--collect-only")
984984
result.stdout.fnmatch_lines(
985985
[
986986
"collected 2 items",
987-
"<Package */tests'>",
988-
" <Module '__init__.py'>",
989-
" <Function 'test_init'>",
990-
" <Module 'test_foo.py'>",
991-
" <Function 'test_foo'>",
987+
"<Package */tests>",
988+
" <Module __init__.py>",
989+
" <Function test_init>",
990+
" <Module test_foo.py>",
991+
" <Function test_foo>",
992992
]
993993
)
994994
result = testdir.runpytest("./tests/test_foo.py", "--collect-only")
995995
result.stdout.fnmatch_lines(
996-
["<Package */tests'>", " <Module 'test_foo.py'>", " <Function 'test_foo'>"]
996+
["<Package */tests>", " <Module test_foo.py>", " <Function test_foo>"]
997997
)
998998
assert "test_init" not in result.stdout.str()
999999
result = testdir.runpytest("./tests/__init__.py", "--collect-only")
10001000
result.stdout.fnmatch_lines(
1001-
["<Package */tests'>", " <Module '__init__.py'>", " <Function 'test_init'>"]
1001+
["<Package */tests>", " <Module __init__.py>", " <Function test_init>"]
10021002
)
10031003
assert "test_foo" not in result.stdout.str()
10041004

testing/test_terminal.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def test_func():
263263
)
264264
result = testdir.runpytest("--collect-only")
265265
result.stdout.fnmatch_lines(
266-
["<Module 'test_collectonly_basic.py'>", " <Function 'test_func'>"]
266+
["<Module test_collectonly_basic.py>", " <Function test_func>"]
267267
)
268268

269269
def test_collectonly_skipped_module(self, testdir):
@@ -307,11 +307,10 @@ def test_method(self):
307307
assert result.ret == 0
308308
result.stdout.fnmatch_lines(
309309
[
310-
"*<Module '*.py'>",
311-
"* <Function 'test_func1'*>",
312-
"* <Class 'TestClass'>",
313-
# "* <Instance '()'>",
314-
"* <Function 'test_method'*>",
310+
"*<Module *.py>",
311+
"* <Function test_func1>",
312+
"* <Class TestClass>",
313+
"* <Function test_method>",
315314
]
316315
)
317316

0 commit comments

Comments
 (0)