diff --git a/changelog/4458.bugfix.rst b/changelog/4458.bugfix.rst new file mode 100644 index 000000000..891fb9a2f --- /dev/null +++ b/changelog/4458.bugfix.rst @@ -0,0 +1 @@ +Display actual test ids in ``--collect-only``. diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index 86e541152..77e6f02c1 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -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. diff --git a/testing/python/collect.py b/testing/python/collect.py index 2e5d62dd5..4ce3d120d 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -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"" + def test_issue197_parametrize_emptyset(self, testdir): testdir.makepyfile( """ diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 0d5b6037f..243d50d2d 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -474,9 +474,9 @@ class TestMetafunc(object): result = testdir.runpytest("--collect-only", SHOW_PYTEST_WARNINGS_ARG) result.stdout.fnmatch_lines( [ - "", - " ", - " ", + "", + " ", + " ", "*test_parametrize_ids_exception.py:6: *parameter arg at position 0*", "*test_parametrize_ids_exception.py:6: *parameter arg at position 1*", ] diff --git a/testing/test_collection.py b/testing/test_collection.py index fae23025e..473883b0d 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -950,10 +950,10 @@ def test_collect_init_tests(testdir): [ "collected 2 items", "", - " ", - " ", - " ", + " ", + " ", + " ", + " ", ] ) result = testdir.runpytest("./tests", "--collect-only") @@ -961,10 +961,10 @@ def test_collect_init_tests(testdir): [ "collected 2 items", "", - " ", - " ", - " ", + " ", + " ", + " ", + " ", ] ) # Ignores duplicates with "." and pkginit (#4310). @@ -972,11 +972,11 @@ def test_collect_init_tests(testdir): result.stdout.fnmatch_lines( [ "collected 2 items", - "", - " ", - " ", - " ", - " ", + "", + " ", + " ", + " ", + " ", ] ) # Same as before, but different order. @@ -984,21 +984,21 @@ def test_collect_init_tests(testdir): result.stdout.fnmatch_lines( [ "collected 2 items", - "", - " ", - " ", - " ", - " ", + "", + " ", + " ", + " ", + " ", ] ) result = testdir.runpytest("./tests/test_foo.py", "--collect-only") result.stdout.fnmatch_lines( - ["", " ", " "] + ["", " ", " "] ) assert "test_init" not in result.stdout.str() result = testdir.runpytest("./tests/__init__.py", "--collect-only") result.stdout.fnmatch_lines( - ["", " ", " "] + ["", " ", " "] ) assert "test_foo" not in result.stdout.str() diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 86ec1cd07..60a64cdd6 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -263,7 +263,7 @@ class TestCollectonly(object): ) result = testdir.runpytest("--collect-only") result.stdout.fnmatch_lines( - ["", " "] + ["", " "] ) def test_collectonly_skipped_module(self, testdir): @@ -307,11 +307,10 @@ class TestCollectonly(object): assert result.ret == 0 result.stdout.fnmatch_lines( [ - "*", - "* ", - "* ", - # "* ", - "* ", + "*", + "* ", + "* ", + "* ", ] )