Skip to content

Commit 6c8077d

Browse files
dajoseDavid Diaz Barquero
authored andcommitted
add ini option cpp_verbose to print tests output right after test
1 parent 5eb9972 commit 6c8077d

4 files changed

Lines changed: 27 additions & 0 deletions

File tree

pytest_cpp/plugin.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def pytest_addoption(parser):
8484
default=(),
8585
help="command that wraps the cpp binary",
8686
)
87+
parser.addini(
88+
"cpp_verbose",
89+
type="bool",
90+
default=False,
91+
help="print the test output right after it ran, requieres -s",
92+
)
8793

8894

8995
class CppFile(pytest.File):
@@ -135,6 +141,9 @@ def runtest(self):
135141
# Report the c++ output in its own sections
136142
self.add_report_section("call", "c++", output)
137143

144+
if self.config.getini("cpp_verbose"):
145+
print(output)
146+
138147
if failures:
139148
raise CppFailureError(failures)
140149

tests/boost_success.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
BOOST_AUTO_TEST_CASE( test_success_1 )
66
{
7+
printf("Just saying hi from boost\n");
78
BOOST_CHECK( 2 * 3 == 6 );
89
}
910

tests/gtest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class FooTest : public ::testing::Test {
1010
// Tests that the Foo::Bar() method does Abc.
1111
TEST_F(FooTest, test_success) {
1212
EXPECT_EQ(2 * 3, 6);
13+
printf("Just saying hi from gtest\n");
1314
}
1415

1516
// Tests that the Foo::Bar() method does Abc.

tests/test_pytest_cpp.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,22 @@ def test_output_section(testdir, exes):
521521
)
522522

523523

524+
def test_cpp_verbose(testdir, exes):
525+
exes.get("boost_success")
526+
exes.get("gtest")
527+
528+
testdir.makeini(
529+
"""
530+
[pytest]
531+
cpp_files = gtest* boost*
532+
"""
533+
)
534+
result = testdir.runpytest("-k", "success", "-s", "-o", "cpp_verbose=true")
535+
result.stdout.fnmatch_lines(
536+
["*Just saying hi from boost", "*Just saying hi from gtest"]
537+
)
538+
539+
524540
class TestError:
525541
def test_get_whitespace(self):
526542
assert error.get_left_whitespace(" foo") == " "

0 commit comments

Comments
 (0)