diff --git a/pytest_testdox/plugin.py b/pytest_testdox/plugin.py index e01de36..85f3801 100644 --- a/pytest_testdox/plugin.py +++ b/pytest_testdox/plugin.py @@ -128,6 +128,15 @@ def pytest_runtest_logreport(self, report): self._tw.line(str(result)) + def pytest_runtest_logstart(self, nodeid, location): + # Ensure that the path is printed before the + # 1st test of a module starts running. + self.write_fspath_result(nodeid, "") + + # To support Pytest < 6.0.0 + if hasattr(self, 'flush'): + self.flush() + def _first(iterator): try: diff --git a/tests/test_plugin.py b/tests/test_plugin.py index ec8671c..62e5946 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -11,7 +11,7 @@ def testdir(self, testdir): testdir.makeconftest( """ pytest_plugins = 'pytest_testdox.plugin' - """ + """ ) return testdir @@ -20,7 +20,7 @@ def test_should_print_a_green_passing_test(self, testdir): """ def test_a_feature_is_working(): assert True - """ + """ ) result = testdir.runpytest('--force-testdox') @@ -33,7 +33,7 @@ def test_should_print_a_red_failing_test(self, testdir): """ def test_a_failed_test_of_a_feature(): assert False - """ + """ ) result = testdir.runpytest('--force-testdox') @@ -49,7 +49,7 @@ def test_should_print_a_yellow_skipped_test(self, testdir): @pytest.mark.skip def test_a_skipped_test(): pass - """ + """ ) result = testdir.runpytest('--force-testdox') @@ -62,7 +62,7 @@ def test_should_not_print_colors_when_disabled_by_parameter(self, testdir): """ def test_a_feature_is_working(): assert True - """ + """ ) result = testdir.runpytest('--color=no', '--force-testdox') @@ -73,13 +73,13 @@ def test_should_output_plaintext_using_a_config_option(self, testdir): """ [pytest] testdox_format=plaintext - """ + """ ) testdir.makepyfile( """ def test_a_feature_is_working(): assert True - """ + """ ) result = testdir.runpytest('--force-testdox') @@ -96,7 +96,7 @@ def test_foo(self): class TestBar: def test_bar(self): pass - """ + """ ) result = testdir.runpytest('--force-testdox') @@ -114,7 +114,7 @@ def test_should_print_the_module_name_of_a_test_without_class( test_module_name=""" def test_a_failed_test_of_a_feature(): assert False - """, + """, ) result = testdir.runpytest('--force-testdox') @@ -126,7 +126,7 @@ def test_should_print_test_summary(self, testdir): test_module_name=""" def test_a_passing_test(): assert True - """, + """, ) result = testdir.runpytest('--force-testdox') @@ -139,7 +139,7 @@ def test_should_use_python_patterns_configuration(self, testdir): python_classes=Describe* python_files=*spec.py python_functions=it* - """ + """ ) testdir.makefile( '.py', @@ -147,7 +147,7 @@ def test_should_use_python_patterns_configuration(self, testdir): class DescribeTest: def it_runs(self): pass - """, + """, ) result = testdir.runpytest('--force-testdox') @@ -167,7 +167,7 @@ def test_should_override_test_titles_with_title_mark(self, testdir): ''') def test_a_passing_test(): assert True - """.format( + """.format( constants.TITLE_MARK ), ) @@ -190,7 +190,7 @@ class TestClass: def test_foo(self): pass - """.format( + """.format( constants.CLASS_NAME_MARK ), ) @@ -211,7 +211,7 @@ def test_should_override_test_titles_with_title_mark_parametrize( @pytest.mark.{}('should pass with parameters') def test_a_passing_test(par): assert True - """.format( + """.format( constants.TITLE_MARK ), ) @@ -231,7 +231,7 @@ def test_decorator_order_should_not_affect_parametrize(self, testdir): @pytest.mark.parametrize('par', ['param1', 'param2']) def test_a_passing_test(par): assert True - """.format( + """.format( constants.TITLE_MARK ), ) @@ -246,7 +246,7 @@ def test_should_not_enable_plugin_when_test_run_out_of_tty(self, testdir): """ def test_a_feature_is_working(): assert True - """ + """ ) result = testdir.runpytest('--testdox') @@ -275,3 +275,18 @@ def test_a_feature_is_working_in_another_module(self): word_count = Counter(result.stdout.lines) assert word_count['Foo'] == 2 + + def test_verbose_mode_should_not_affect_the_filename_output(self, testdir): + file = testdir.makepyfile( + """ + def test_foo(): + assert True + + def test_bar(): + assert True + """ + ) + + result = testdir.runpytest('--verbose', '--force-testdox') + + result.stdout.re_match_lines(r'^' + file.basename + r'\s+$')