Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/_pytest/junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ def record_testreport(self, testreport):
attrs = {
"classname": ".".join(classnames),
"name": bin_xml_escape(names[-1]),
"file": testreport.location[0],
#"file": testreport.location[0], # file is not valid in testcase
}
if testreport.location[1] is not None:
attrs["line"] = testreport.location[1]
#attrs["line"] = testreport.location[1] # line is not a valid attr in testcase
pass
if hasattr(testreport, "url"):
attrs["url"] = testreport.url
self.attrs = attrs
Expand Down Expand Up @@ -538,7 +539,7 @@ def pytest_sessionfinish(self):
name=self.suite_name,
errors=self.stats["error"],
failures=self.stats["failure"],
skips=self.stats["skipped"],
skipped=self.stats["skipped"],
tests=numtests,
time="%.3f" % suite_time_delta,
).unicode(indent=0)
Expand Down
64 changes: 18 additions & 46 deletions testing/test_junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_xpass():
result, dom = runandparse(testdir)
assert result.ret
node = dom.find_first_by_tag("testsuite")
node.assert_attr(name="pytest", errors=0, failures=1, skips=2, tests=5)
node.assert_attr(name="pytest", errors=0, failures=1, skipped=2, tests=5)

def test_summing_simple_with_errors(self, testdir):
testdir.makepyfile(
Expand All @@ -129,7 +129,7 @@ def test_xpass():
result, dom = runandparse(testdir)
assert result.ret
node = dom.find_first_by_tag("testsuite")
node.assert_attr(name="pytest", errors=1, failures=2, skips=1, tests=5)
node.assert_attr(name="pytest", errors=1, failures=2, skipped=1, tests=5)

def test_timing_function(self, testdir):
testdir.makepyfile(
Expand Down Expand Up @@ -167,8 +167,6 @@ def test_function(arg):
node.assert_attr(errors=1, tests=1)
tnode = node.find_first_by_tag("testcase")
tnode.assert_attr(
file="test_setup_error.py",
line="5",
classname="test_setup_error",
name="test_function",
)
Expand All @@ -194,8 +192,6 @@ def test_function(arg):
node = dom.find_first_by_tag("testsuite")
tnode = node.find_first_by_tag("testcase")
tnode.assert_attr(
file="test_teardown_error.py",
line="6",
classname="test_teardown_error",
name="test_function",
)
Expand Down Expand Up @@ -239,11 +235,9 @@ def test_skip():
result, dom = runandparse(testdir)
assert result.ret == 0
node = dom.find_first_by_tag("testsuite")
node.assert_attr(skips=1)
node.assert_attr(skipped=1)
tnode = node.find_first_by_tag("testcase")
tnode.assert_attr(
file="test_skip_contains_name_reason.py",
line="1",
classname="test_skip_contains_name_reason",
name="test_skip",
)
Expand All @@ -262,11 +256,9 @@ def test_skip():
result, dom = runandparse(testdir)
assert result.ret == 0
node = dom.find_first_by_tag("testsuite")
node.assert_attr(skips=1)
node.assert_attr(skipped=1)
tnode = node.find_first_by_tag("testcase")
tnode.assert_attr(
file="test_mark_skip_contains_name_reason.py",
line="1",
classname="test_mark_skip_contains_name_reason",
name="test_skip",
)
Expand All @@ -286,11 +278,9 @@ def test_skip():
result, dom = runandparse(testdir)
assert result.ret == 0
node = dom.find_first_by_tag("testsuite")
node.assert_attr(skips=1)
node.assert_attr(skipped=1)
tnode = node.find_first_by_tag("testcase")
tnode.assert_attr(
file="test_mark_skipif_contains_name_reason.py",
line="2",
classname="test_mark_skipif_contains_name_reason",
name="test_skip",
)
Expand Down Expand Up @@ -325,8 +315,6 @@ def test_method(self):
node.assert_attr(failures=1)
tnode = node.find_first_by_tag("testcase")
tnode.assert_attr(
file="test_classname_instance.py",
line="1",
classname="test_classname_instance.TestClass",
name="test_method",
)
Expand All @@ -340,8 +328,6 @@ def test_classname_nested_dir(self, testdir):
node.assert_attr(failures=1)
tnode = node.find_first_by_tag("testcase")
tnode.assert_attr(
file=os.path.join("sub", "test_hello.py"),
line="0",
classname="sub.test_hello",
name="test_func",
)
Expand Down Expand Up @@ -381,8 +367,6 @@ def test_fail():
node.assert_attr(failures=1, tests=1)
tnode = node.find_first_by_tag("testcase")
tnode.assert_attr(
file="test_failure_function.py",
line="3",
classname="test_failure_function",
name="test_fail",
)
Expand Down Expand Up @@ -442,8 +426,6 @@ def test_func(arg1):

tnode = node.find_nth_by_tag("testcase", index)
tnode.assert_attr(
file="test_failure_escape.py",
line="1",
classname="test_failure_escape",
name="test_func[%s]" % char,
)
Expand All @@ -467,15 +449,11 @@ def test_hello(self):
node.assert_attr(failures=1, tests=2)
tnode = node.find_first_by_tag("testcase")
tnode.assert_attr(
file="test_junit_prefixing.py",
line="0",
classname="xyz.test_junit_prefixing",
name="test_func",
)
tnode = node.find_nth_by_tag("testcase", 1)
tnode.assert_attr(
file="test_junit_prefixing.py",
line="3",
classname="xyz.test_junit_prefixing." "TestHello",
name="test_hello",
)
Expand All @@ -491,11 +469,9 @@ def test_xfail():
result, dom = runandparse(testdir)
assert not result.ret
node = dom.find_first_by_tag("testsuite")
node.assert_attr(skips=1, tests=1)
node.assert_attr(skipped=1, tests=1)
tnode = node.find_first_by_tag("testcase")
tnode.assert_attr(
file="test_xfailure_function.py",
line="1",
classname="test_xfailure_function",
name="test_xfail",
)
Expand Down Expand Up @@ -534,11 +510,9 @@ def test_xpass():
result, dom = runandparse(testdir)
# assert result.ret
node = dom.find_first_by_tag("testsuite")
node.assert_attr(skips=0, tests=1)
node.assert_attr(skipped=0, tests=1)
tnode = node.find_first_by_tag("testcase")
tnode.assert_attr(
file="test_xfailure_xpass.py",
line="1",
classname="test_xfailure_xpass",
name="test_xpass",
)
Expand All @@ -555,11 +529,9 @@ def test_xpass():
result, dom = runandparse(testdir)
# assert result.ret
node = dom.find_first_by_tag("testsuite")
node.assert_attr(skips=0, tests=1)
node.assert_attr(skipped=0, tests=1)
tnode = node.find_first_by_tag("testcase")
tnode.assert_attr(
file="test_xfailure_xpass_strict.py",
line="1",
classname="test_xfailure_xpass_strict",
name="test_xpass",
)
Expand All @@ -573,7 +545,7 @@ def test_collect_error(self, testdir):
node = dom.find_first_by_tag("testsuite")
node.assert_attr(errors=1, tests=1)
tnode = node.find_first_by_tag("testcase")
tnode.assert_attr(file="test_collect_error.py", name="test_collect_error")
tnode.assert_attr(name="test_collect_error")
assert tnode["line"] is None
fnode = tnode.find_first_by_tag("error")
fnode.assert_attr(message="collection failure")
Expand Down Expand Up @@ -757,7 +729,7 @@ def repr_failure(self, excinfo):
result, dom = runandparse(testdir)
assert result.ret
node = dom.find_first_by_tag("testsuite")
node.assert_attr(errors=0, failures=1, skips=0, tests=1)
node.assert_attr(errors=0, failures=1, skipped=0, tests=1)
tnode = node.find_first_by_tag("testcase")
tnode.assert_attr(name="myfile.xyz")
fnode = tnode.find_first_by_tag("failure")
Expand Down Expand Up @@ -1119,19 +1091,19 @@ def test_pass():
assert "INTERNALERROR" not in result.stdout.str()

items = sorted(
"%(classname)s %(name)s %(file)s" % x for x in dom.find_by_tag("testcase")
"%(classname)s %(name)s" % x for x in dom.find_by_tag("testcase")
)
import pprint

pprint.pprint(items)
assert items == [
u"conftest a conftest.py",
u"conftest a conftest.py",
u"conftest b conftest.py",
u"test_fancy_items_regression a test_fancy_items_regression.py",
u"test_fancy_items_regression a test_fancy_items_regression.py",
u"test_fancy_items_regression b test_fancy_items_regression.py",
u"test_fancy_items_regression test_pass" u" test_fancy_items_regression.py",
u"conftest a",
u"conftest a",
u"conftest b",
u"test_fancy_items_regression a",
u"test_fancy_items_regression a",
u"test_fancy_items_regression b",
u"test_fancy_items_regression test_pass" u"",
]


Expand Down