Skip to content

Option to disable impending change #10421

@aroberge

Description

@aroberge

I just installed the latest pytest version (7.2.0) and saw multiple examples which stating the following:

 PytestReturnNotNoneWarning: Expected None, but test_example.py::test returned 'Hello', which will be an error in a future version of pytest.  Did you mean to use `assert` instead of `return`?

In one of my projects, I have over 400 tests which do use assert and return. The return statement is used to create documentation. See for example https://friendly-traceback.github.io/docs/tracebacks_en_3.9.html

A typical test function will have the following outline:

import friendly_traceback

def test_example():
    try:
        SpecificException("specific message")  # simplification for this issue on Github
    except SpecificException as e:
        message = str(e)
        friendly_traceback.explain_traceback(redirect="capture")
    
    result = friendly_traceback.get_output()
    assert "specific message" in result  # often varies in different Python versions
    if friendly_traceback.get_lang() == "en":
        assert "expected explanation in English from friendly_traceback" in result
    return result, message

If you browse the documentation of friendly_traceback, you will see that these 400+ tests help to document what the output is for various Python version and languages (English, French, Spanish, ...). This is invaluable to understand in context if a translation has been done correctly.
Returning the message helps to document changes from one Python version to the next.

I would really like if there were a way to enable having test functions returning something else than None not being an error (and being able to turn off PytestReturnNotNoneWarning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions