Skip to content

Returning fig is incompatible with pytest 7.2 (when test uses marker but pytest-mpl not installed) #183

Closed

Description

@pllim

As @WilliamJamieson discovered in astropy/astropy#13892 , we now see PytestReturnNotNoneWarning with pytest 7.2 that will eventually become an exception in future releases. If there is no way to opt out (asking at pytest-dev/pytest#10427), can this plugin still work without return fig?

Activity

  1. nicoddemus commented on Oct 25, 2022

    @nicoddemus

    Hey, pytest maintainer here.

    Here is the related code in pytest:

    https://github.com/pytest-dev/pytest/blob/f07017f91b6af5a7c6942868cb61aea72be4ac31/src/_pytest/python.py#L188-L205

    I see pytest-mpl uses a hookwrapper over pytest_runtest_call, what might be needed is to make a hookwrapper over pytest_pyfunc_call which also sets the return value to None.

    https://pluggy.readthedocs.io/en/stable/#wrappers

  2. WilliamJamieson commented on Oct 25, 2022

    @WilliamJamieson

    I don't think there is an issue here. If pytest-mpl is installed, the "figure" tests in astropy don't produce the PytestReturnNotNoneWarning.

    The issue in astropy/astropy#13892 appears to be that one of the CI jobs which uses remote-data (unskipping the figure tests) does install have pytest-mpl. All the tests at issue use this wrapper: https://github.com/astropy/astropy/blob/8a3cd43d45722dbb2fbc03e63bfef61320ac1b0e/astropy/tests/figures/helpers.py#L8-L44, which apparently does not require pytest-mpl even though it seems to be using it (https://github.com/astropy/astropy/blob/8a3cd43d45722dbb2fbc03e63bfef61320ac1b0e/astropy/tests/figures/helpers.py#L29-L32).

    There are two options:

    1. Add a skip in this wrapper so that if pytest-mpl is not installed, then these tests get skipped.
    2. Add pytest-mpl as a dependency to the CI jobs which use remote-data.

    My preference is for option 1.

  3. pllim commented on Oct 25, 2022

    @pllim
    ContributorAuthor

    My vote is also 1 since I don't find these tests very useful without this plugin.

  4. WilliamJamieson commented on Oct 25, 2022

    @WilliamJamieson

    The only thing that those tests do is exercise some of the astropy.visualization code meaning it "tests" that it doesn't raise an error in matplotlib. But the circle CI (the one that uses pytest-mpl) also runs these tests, but actually tests the resulting figures.

  5. pllim commented on Oct 25, 2022

    @pllim
    ContributorAuthor

    Sure, but CircleCI one is the true purpose of those tests. I think "just see if it crash or not" is partly covered by doctest anyway. Though if you are relying on the job without pytest-mpl to calculate coverage... 💭

  6. pllim commented on Oct 25, 2022

    @pllim
    ContributorAuthor

    Then again, (2) isn't a foolproof solution. Anyone running these tests with remote data locally but didn't install pytest-mpl would have the same problem.

  7. astrofrog commented on Oct 25, 2022

    @astrofrog
    Collaborator

    I would be fine with 1

  8. WilliamJamieson commented on Oct 25, 2022

    @WilliamJamieson

    Alright, here is a weird pytest-mpl issue:

    1. If I don't have pytest-mpl installed import pytest_mpl fails as expected.
    2. If I then pip install pytest-mpl and then do a import pytest_mpl it works (what HAS_PYTEST_MPL does).
    3. However, if I then pip uninstall pytest-mpl and then don import pytest_mpl it works again. Moreover, the skips for no pytest-mpl do not occur and we get the error from pytest that we saw before (This is wrt the astropy branch Fix testing for pytest 7.2 support astropy/astropy#13892).
    4. Reinstalling with pip install pytest-mpl solves the failing unit tests.

    I have to create a completely new environment in order for the import pytest_mpl to start failing again...

  9. pllim commented on Oct 25, 2022

    @pllim
    ContributorAuthor

    #183 (comment)

    FWIW, I cannot reproduce this problem but I use conda and you don't. 🤷

  10. changed the title [-]Returning fig is incompatible with pytest 7.2[/-] [+]Returning fig is incompatible with pytest 7.2 (when test uses marker but pytest-mpl not installed)[/+] on Oct 25, 2022
  11. ConorMacBride commented on Nov 3, 2022

    @ConorMacBride
    Member

    As already noted, this issue only occurs when pytest-mpl is not installed. I've opened a PR to close this issue. It adds the following to the docs:

    If pytest-mpl is not installed, the image comparison tests will cause pytest to show a warning, PytestReturnNotNoneWarning. Installing pytest-mpl will solve this issue. Alternativly, the image comparison tests can be deselected by running pytest with -m "not mpl_image_compare".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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