Skip to content

Commit

Permalink
Display actual test ids in --collect-only
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Nov 25, 2018
1 parent 59f6523 commit e9b2475
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 35 deletions.
1 change: 1 addition & 0 deletions changelog/4458.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Display actual test ids in ``--collect-only``.
2 changes: 1 addition & 1 deletion src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _getcustomclass(self, name):
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.
Expand Down
18 changes: 13 additions & 5 deletions testing/python/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,26 +489,34 @@ def __call__(self, tmpdir):
]
)

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(
"""
Expand Down
6 changes: 3 additions & 3 deletions testing/python/metafunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,9 @@ def test_foo(arg):
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*",
]
Expand Down
40 changes: 20 additions & 20 deletions testing/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,55 +950,55 @@ 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")
result.stdout.fnmatch_lines(
[
"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).
result = testdir.runpytest("./tests", ".", "--collect-only")
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.
result = testdir.runpytest(".", "tests", "--collect-only")
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()

Expand Down
11 changes: 5 additions & 6 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def test_func():
)
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):
Expand Down Expand Up @@ -307,11 +307,10 @@ def test_method(self):
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>",
]
)

Expand Down

0 comments on commit e9b2475

Please sign in to comment.