Skip to content

Commit d24a187

Browse files
authored
Catch2: fix multiple section failures (#112)
1 parent 934a1bc commit d24a187

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# UNRELEASED
2+
3+
- Catch2: fix issue with multiple test failures, and support multiple "SECTION" tests. ([#112](https://github.com/pytest-dev/pytest-cpp/pull/112))
4+
15
# 2.3.0 (2023-01-30)
26

37
- New `cpp_harness_collect` configuration option allows users to add prefix arguments to run C++ test executables, allowing to use additional tools like `wine` of `qemu` for a test runners in cross-platform development.

src/pytest_cpp/catch2.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,24 +96,6 @@ def run_test(
9696
)
9797
except subprocess.CalledProcessError as e:
9898
output = e.output
99-
if e.returncode != 1:
100-
msg = (
101-
"Internal Error: calling {executable} "
102-
"for test {test_id} failed (returncode={returncode}):\n"
103-
"{output}"
104-
)
105-
failure = Catch2Failure(
106-
executable,
107-
0,
108-
msg.format(
109-
executable=executable,
110-
test_id=test_id,
111-
output=e.output,
112-
returncode=e.returncode,
113-
),
114-
)
115-
116-
return [failure], output
11799

118100
results = self._parse_xml(xml_filename)
119101

@@ -151,7 +133,7 @@ def _parse_xml(
151133
test_result = test_case.find("OverallResult")
152134
failures = []
153135
if test_result is not None and test_result.attrib["success"] == "false":
154-
test_checks = test_case.findall("Expression")
136+
test_checks = test_case.findall(".//Expression")
155137
for check in test_checks:
156138
file_name = check.attrib["filename"]
157139
line_num = int(check.attrib["line"])

tests/catch2_failure.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ TEST_CASE( "Factorials are computed", "[factorial]" ) {
1212
REQUIRE( Factorial(3) == 6 );
1313
REQUIRE( Factorial(10) == 3628800 );
1414
}
15+
16+
TEST_CASE( "Failed Sections" ) {
17+
SECTION( "failed 1" ) {
18+
REQUIRE(false);
19+
}
20+
21+
SECTION( "failed 2" ) {
22+
REQUIRE(false);
23+
}
24+
}

tests/catch2_success.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,13 @@ TEST_CASE( "Factorials are computed", "[factorial]" ) {
1111
REQUIRE( Factorial(3) == 6 );
1212
REQUIRE( Factorial(10) == 3628800 );
1313
}
14+
15+
TEST_CASE( "Passed Sections" ) {
16+
SECTION( "passed 1" ) {
17+
REQUIRE(true);
18+
}
19+
20+
SECTION( "passed 2" ) {
21+
REQUIRE(true);
22+
}
23+
}

tests/test_pytest_cpp.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ def get_file_reference(self):
5757
(BoostTestFacade(), "boost_success", ["boost_success"]),
5858
(BoostTestFacade(), "boost_error", ["boost_error"]),
5959
(BoostTestFacade(), "boost_fixture_setup_error", ["boost_fixture_setup_error"]),
60-
(Catch2Facade(), "catch2_success", ["Factorials are computed"]),
60+
(
61+
Catch2Facade(),
62+
"catch2_success",
63+
["Factorials are computed", "Passed Sections"],
64+
),
6165
],
6266
)
6367
def test_list_tests(facade, name, expected, exes):
@@ -610,6 +614,9 @@ def test_catch2_failure(exes):
610614

611615
assert fail1.get_file_reference() == ("catch2_failure.cpp", 9)
612616

617+
failures, _ = facade.run_test(exes.get("catch2_failure"), "Failed Sections")
618+
assert len(failures) == 2
619+
613620

614621
class TestError:
615622
def test_get_whitespace(self):

0 commit comments

Comments
 (0)