Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove FAILURES from pytest output

Tags:

python

pytest

Pytest is new to me. We try to verify that we have all expected files in a project.

I like every part of the pytest output except for the detailed FAILURES that will confuse our non-programmers.

How can we suppress the FAILURES output?

Current code:

import os.path
import pytest

spec = {"expected_files": ["Dockerfile", "Duckerfile", "Daskerfile"]}

@pytest.mark.parametrize("expected_file", spec['expected_files'])
def test_expected_file_is_in_project(expected_file):
    assert os.path.isfile(expected_file), "File \""+expected_file+"\" not found in project"

Output after running the "pytest -v" command

Output after running the "pytest -v" command

like image 428
Håvard Avatar asked Apr 24 '26 09:04

Håvard


1 Answers

You may run pytest with the traceback (tb) option set to no in order to suppress the traceback reporting, i.e.:

pytest --tb=no

Check out the Modifying Python traceback printing section of the pytest documentation.

like image 173
dspencer Avatar answered Apr 25 '26 23:04

dspencer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!