Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pytest>=7.0.0 deprecation warnigs #3223

Closed
wants to merge 2 commits into from
Closed

Fix pytest>=7.0.0 deprecation warnigs #3223

wants to merge 2 commits into from

Conversation

bibajz
Copy link
Contributor

@bibajz bibajz commented Jan 24, 2022

As discussed in #3222, this fixes the relevant deprecations.

The logic in escalation.py is quite convoluted, but I do not know if anyone is using _pytest without importing pytest, so to be super safe, I except both AttributeError and KeyError.

Cheers,
Libor

Even though using `_pytest.config.Config` is not deprecated in
pytest>=7, this limits all usages of `_pytest` to truly necessary
ones.
@jab
Copy link
Contributor

jab commented Feb 16, 2022

I'm still hitting this after upgrading to hypothesis-6.36.2. Here's an example:

❯ pytest --benchmark-disable -x -k pickle
================================================================================= test session starts ==================================================================================
platform darwin -- Python 3.10.1, pytest-7.0.1, pluggy-1.0.0 -- /Users/jab/src/bidict/.tox/py310/bin/python
cachedir: .pytest_cache
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
hypothesis profile 'custom' -> max_examples=200, database=DirectoryBasedExampleDatabase('/Users/jab/src/bidict/.hypothesis/examples')
rootdir: /Users/jab/src/bidict, configfile: pytest.ini, testpaths: bidict, tests
plugins: benchmark-3.4.1, hypothesis-6.36.2, icdiff-0.5, cov-3.0.0
collected 149 items / 141 deselected / 8 selected

tests/test_microbenchmarks.py::test_pickle[99] PASSED                                                                                                                            [ 12%]
tests/test_microbenchmarks.py::test_pickle[999] PASSED                                                                                                                           [ 25%]
tests/test_microbenchmarks.py::test_pickle[9999] PASSED                                                                                                                          [ 37%]
tests/test_microbenchmarks.py::test_unpickle[99] PASSED                                                                                                                          [ 50%]
tests/test_microbenchmarks.py::test_unpickle[999] PASSED                                                                                                                         [ 62%]
tests/test_microbenchmarks.py::test_unpickle[9999] PASSED                                                                                                                        [ 75%]
tests/property_tests/test_properties.py::test_pickle FAILED                                                                                                                      [ 87%]

======================================================================================= FAILURES =======================================================================================
_____________________________________________________________________________________ test_pickle ______________________________________________________________________________________

    @given(st.BIDICTS)
>   @example(BIDICT_TYPE_WHOSE_MODULE_HAS_REF_TO_INV_CLS({1: 'one'}).inverse)

tests/property_tests/test_properties.py:466:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py310/lib/python3.10/site-packages/hypothesis/internal/escalation.py:140: in format_exception
    return str(item.repr_failure(ExceptionInfo((type(err), err, tb)))) + "\n"
.tox/py310/lib/python3.10/site-packages/_pytest/_code/code.py:463: in __init__
    check_ispytest(_ispytest)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

ispytest = False

    def check_ispytest(ispytest: bool) -> None:
        if not ispytest:
>           warn(PRIVATE, stacklevel=3)
E           pytest.PytestDeprecationWarning: A private pytest class or function was used.

.tox/py310/lib/python3.10/site-packages/_pytest/deprecated.py:155: PytestDeprecationWarning
-------------------------------------------------------------------------------------- Hypothesis --------------------------------------------------------------------------------------
Falsifying explicit example: test_pickle(
    bi=UserBidictNotOwnInverseInv({'one': 1}),
)
=============================================================================== short test summary info ================================================================================
FAILED tests/property_tests/test_properties.py::test_pickle - pytest.PytestDeprecationWarning: A private pytest class or function was used.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
===================================================================== 1 failed, 6 passed, 141 deselected in 0.63s ======================================================================

It looks like the following code from "hypothesis/internal/escalation.py:140: in format_exception"...

return str(item.repr_failure(ExceptionInfo((type(err), err, tb)))) + "\n"

is the culprit?

@Zac-HD
Copy link
Member

Zac-HD commented Feb 18, 2022

@jab - can you confirm that the patch above fixes this for you?

@aarchiba
Copy link
Contributor

I think the warning may still be arising? At least when I use pytest -W error on PINT I get:

../pint-env/lib/python3.6/site-packages/_pytest/_code/code.py:463: in __init__
    check_ispytest(_ispytest)
../pint-env/lib/python3.6/site-packages/_pytest/deprecated.py:155: in check_ispytest
    warn(PRIVATE, stacklevel=3)
../pint-env/lib/python3.6/site-packages/_pytest/runner.py:340: in from_call
    result: Optional[TResult] = func()
../pint-env/lib/python3.6/site-packages/_pytest/runner.py:261: in <lambda>
    lambda: ihook(item=item, **kwds), when=when, reraise=reraise
../pint-env/lib/python3.6/site-packages/pluggy/_hooks.py:265: in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
../pint-env/lib/python3.6/site-packages/pluggy/_manager.py:80: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
../pint-env/lib/python3.6/site-packages/_pytest/runner.py:176: in pytest_runtest_call
    raise e
../pint-env/lib/python3.6/site-packages/_pytest/runner.py:168: in pytest_runtest_call
    item.runtest()
../pint-env/lib/python3.6/site-packages/_pytest/python.py:1718: in runtest
    self.ihook.pytest_pyfunc_call(pyfuncitem=self)
../pint-env/lib/python3.6/site-packages/pluggy/_hooks.py:265: in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
../pint-env/lib/python3.6/site-packages/pluggy/_manager.py:80: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
../pint-env/lib/python3.6/site-packages/_pytest/python.py:192: in pytest_pyfunc_call
    result = testfunction(**testargs)
tests/test_precision.py:332: in test_time_from_longdouble_utc
    @example(format="pulsar_mjd", i_f=(40000, 0.7333333333333333))
../pint-env/lib/python3.6/site-packages/_pytest/_code/code.py:463: in __init__
    check_ispytest(_ispytest)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

ispytest = False

    def check_ispytest(ispytest: bool) -> None:
        if not ispytest:
>           warn(PRIVATE, stacklevel=3)
E           pytest.PytestDeprecationWarning: A private pytest class or function was used.

../pint-env/lib/python3.6/site-packages/_pytest/deprecated.py:155: PytestDeprecationWarning

I see this with

pytest==7.0.1
hypothesis==6.31.6

If this is a different bug, I'm happy to open a new issue.

@aarchiba
Copy link
Contributor

Er, never mind, it's an old version of hypothesis presumably because the machine only has python3.6 on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants