pytest: Custom markers don't show custom color in 'short test summary info' section

Discussed in https://github.com/pytest-dev/pytest/discussions/9958

<div type='discussions-op-text'>

Originally posted by jeffwright13 May 14, 2022 At the end of a pytest run, you have a section called “short test summary info,” which terminates in a single line that shows final metrics, all color-coded according to outcome. It doesn’t appear as if this final line uses the custom color to color-code tests that are marked with custom markers. I do see that the initial “test session starts” section does color-code those tests, however.

Am I missing something or is this a deficiency in the final section processing code? I’d like to see that final line show my ‘snowflake’ tests in cyan!

Output: Screen Shot 2022-05-14 at 3 07 36 PM

pytest.ini:

[pytest]
markers =
    snowflake: mark a test as flaky (may pass, may fail)

plugin.py:

def pytest_report_teststatus(report: TestReport, config: Config):
    """Put snowflake tests into a separate group from other failures."""
    if report.when == "call" and 'snowflake' in report.keywords.keys() and report.keywords["snowflake"]:
        return 'snowflake', '❄', ('SNOWFLAKE', {"cyan": True})

test1.py:

def test_aa_ok():
    print("This test doesn't have much to say, but it passes - so OK!!")
    pass

test2.py:

def test_aa_ok():
    print("This test doesn't have much to say, and it fails - not OK!!")
    assert 0

test_snowflake.py:

@pytest.mark.snowflake
def test_snowflake_1():
    assert True


@pytest.mark.snowflake
def test_snowflake_2():
    assert False

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 15 (12 by maintainers)

Most upvoted comments

Would that approach also address the lack of coloring in the === short test summary info === section?

This has actually been fixed by #9875 and will be available in pytest 7.2.

@nicoddemus bascially i want to pass the markup that was added in that hook into the status collection as well,

that way we can use the color markup we already use in multiple places (the character and the word) in the summary as well