Skip to content

Commit

Permalink
Merge pull request #73 from renanivo/fix-function-tests
Browse files Browse the repository at this point in the history
Fix logstart on verbose mode
  • Loading branch information
renanivo authored Apr 19, 2022
2 parents 52aff2e + cf2bee9 commit d600635
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
9 changes: 9 additions & 0 deletions pytest_testdox/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
49 changes: 32 additions & 17 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def testdir(self, testdir):
testdir.makeconftest(
"""
pytest_plugins = 'pytest_testdox.plugin'
"""
"""
)
return testdir

Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')

Expand All @@ -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')

Expand All @@ -96,7 +96,7 @@ def test_foo(self):
class TestBar:
def test_bar(self):
pass
"""
"""
)
result = testdir.runpytest('--force-testdox')

Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -139,15 +139,15 @@ def test_should_use_python_patterns_configuration(self, testdir):
python_classes=Describe*
python_files=*spec.py
python_functions=it*
"""
"""
)
testdir.makefile(
'.py',
module_spec="""
class DescribeTest:
def it_runs(self):
pass
""",
""",
)

result = testdir.runpytest('--force-testdox')
Expand All @@ -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
),
)
Expand All @@ -190,7 +190,7 @@ class TestClass:
def test_foo(self):
pass
""".format(
""".format(
constants.CLASS_NAME_MARK
),
)
Expand All @@ -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
),
)
Expand All @@ -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
),
)
Expand All @@ -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')
Expand Down Expand Up @@ -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+$')

0 comments on commit d600635

Please sign in to comment.