From d72c449bba75fec554456f03653d6f76217dc870 Mon Sep 17 00:00:00 2001 From: Silvio Tomatis Date: Tue, 14 May 2019 11:42:58 +0200 Subject: [PATCH] Make sure informative file name make it to the XML report --- pytest_black.py | 2 +- tests/test_black.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pytest_black.py b/pytest_black.py index fc678c9..5bec803 100644 --- a/pytest_black.py +++ b/pytest_black.py @@ -41,7 +41,7 @@ def pytest_unconfigure(config): class BlackItem(pytest.Item, pytest.File): def __init__(self, path, parent): super(BlackItem, self).__init__(path, parent) - self._nodeid += "::BLACK" + self._nodeid += "-BLACK" self.add_marker("black") try: with open("pyproject.toml") as toml_file: diff --git a/tests/test_black.py b/tests/test_black.py index f164ecf..61dcab2 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from xml import dom +from xml.dom.minidom import parse def test_help_message(testdir): @@ -116,3 +118,15 @@ def hello(): result = testdir.runpytest("--black") result.assert_outcomes(skipped=0, passed=1) + + +def test_names(testdir): + """Assert test names are informative about what file was tested + """ + file = testdir.makepyfile('def hello():\n print("Hello, world!")') + file.write(data="\n", mode="a") + + testdir.runpytest("--black", "--junit-xml=test-output.xml") + dom = parse((testdir.tmpdir / "test-output.xml").open()) + test_case = dom.getElementsByTagName("testcase")[0] + assert "test_names.py" in test_case.getAttribute("name")