Python Testing with pytest: 'config' is now a parameter to hook functions (page 101/103)

pytest has changed how hook functions access configuration since the book was published. Following is the correct code for recent versions of pytest. This code occurs on pages 101 and 103.

def pytest_report_header(config):
    """Thank tester for running tests."""
    if config.getoption('nice'):
        return "Thanks for running the tests."


def pytest_report_teststatus(report, config):
    """Turn failures into opportunities."""
    if report.when == 'call':
        if report.failed and config.getoption('nice'):
            return (report.outcome, 'O', 'OPPORTUNITY for improvement')
2 Likes