Page MenuHomeSoftware Heritage

tests: Drop hypothesis < 6 requirement
ClosedPublic

Authored by anlambert on Mar 2 2021, 4:40 PM.

Details

Summary

Ensure tests can be executed using hypothesis >= 6 by suppressing
the function_scoped_fixture health check on test that uses a function
scope fixture in combination with @given.

Diff Detail

Repository
rDCORE Foundations and core functionalities
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Build is green

Patch application report for D5182 (id=18533)

Rebasing onto 576b104799...

Current branch diff-target is up to date.
Changes applied before test
commit a56ef76e37c4e4106352e52df50d005bc1d68c79
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Tue Mar 2 16:27:03 2021 +0100

    tests: Drop hypothesis < 6 requirement
    
    Ensure tests can be executed using hypothesis >= 6 by suppressing
    the function_scoped_fixture health check on test that uses a function
    scope fixture in combination with @given.

See https://jenkins.softwareheritage.org/job/DCORE/job/tests-on-diff/198/ for more details.

This revision is now accepted and ready to land.Mar 3 2021, 8:31 AM
vlorentz requested changes to this revision.Mar 3 2021, 9:22 AM

mypy doesn't like it:

swh/web/tests/conftest.py:41: error: "Type[HealthCheck]" has no attribute "function_scoped_fixture"

You should probably add a # type: ignore

This revision now requires changes to proceed.Mar 3 2021, 9:22 AM

I did not grasp what this was about.
After checking [1], i'm a bit less hazy on what that particular health check is about.

Check if @given has been applied to a test with a pytest function-scoped fixture.
Function-scoped fixtures run once for the whole function, not once per example, and this
is usually not what you want.

Because of this limitation, tests that need to need to set up or reset state for every
example need to do so manually within the test itself, typically using an appropriate
context manager.

So that might help others to inline it ^

What i grasp is that with hypothesis 6, that test was breaking. And as we don't care
here about reset in between tests, we can deactivate that check:

Suppress this health check only in the rare case that you are using a
function-scoped fixture that does not need to be reset between individual examples, but
for some reason you cannot use a wider fixture scope (e.g. session scope, module scope,
class scope).

[1] https://hypothesis.readthedocs.io/en/latest/healthchecks.html?highlight=function_scoped_fixture#hypothesis.HealthCheck.function_scoped_fixture

mypy doesn't like it:

swh/web/tests/conftest.py:41: error: "Type[HealthCheck]" has no attribute "function_scoped_fixture"

You should probably add a # type: ignore

I can't reproduce the mypy error (neither the CI build), which version are you using ?

mypy doesn't like it:

swh/web/tests/conftest.py:41: error: "Type[HealthCheck]" has no attribute "function_scoped_fixture"

You should probably add a # type: ignore

I can't reproduce the mypy error (neither the CI build), which version are you using ?

Nervermind, I got it. The issue happens when using hypothesis < 5.49.

Fix mypy error when using hypothesis < 5.49 and improve commit message.

Build has FAILED

Patch application report for D5182 (id=18550)

Rebasing onto 576b104799...

Current branch diff-target is up to date.
Changes applied before test
commit 58f97df7c0cc1ef92ab657b05fc65c88bb6ac273
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Tue Mar 2 16:27:03 2021 +0100

    tests: Drop hypothesis < 6 requirement
    
    Ensure tests can be executed using hypothesis >= 6 by suppressing
    the function_scoped_fixture health check on test that uses a function
    scope fixture in combination with @given that does not need to be reset
    between individual hypothesis examples.

Link to build: https://jenkins.softwareheritage.org/job/DCORE/job/tests-on-diff/199/
See console output for more information: https://jenkins.softwareheritage.org/job/DCORE/job/tests-on-diff/199/console

Fix issue with mypy when using hypothesis >= 5.49, sigh ...

Build is green

Patch application report for D5182 (id=18556)

Rebasing onto 576b104799...

Current branch diff-target is up to date.
Changes applied before test
commit 76360cc7614f056fc789becf67b138ad7b12bf5f
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Tue Mar 2 16:27:03 2021 +0100

    tests: Drop hypothesis < 6 requirement
    
    Ensure tests can be executed using hypothesis >= 6 by suppressing
    the function_scoped_fixture health check on test that uses a function
    scope fixture in combination with @given that does not need to be reset
    between individual hypothesis examples.

See https://jenkins.softwareheritage.org/job/DCORE/job/tests-on-diff/200/ for more details.

This revision is now accepted and ready to land.Mar 3 2021, 3:29 PM
This revision was automatically updated to reflect the committed changes.