| 1 |
# This file is part of Hypothesis, which may be found at |
| 2 |
# https://github.com/HypothesisWorks/hypothesis/ |
| 3 |
# |
| 4 |
# Copyright the Hypothesis Authors. |
| 5 |
# Individual contributors are listed in AUTHORS.rst and the git log. |
| 6 |
# |
| 7 |
# This Source Code Form is subject to the terms of the Mozilla Public License, |
| 8 |
# v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 9 |
# obtain one at https://mozilla.org/MPL/2.0/. |
| 10 |
|
| 11 |
import pytest |
| 12 |
|
| 13 |
from hypothesis import HealthCheck, given, settings, strategies as st |
| 14 |
|
| 15 |
DB_KEY_TESTCASE = """ |
| 16 |
from hypothesis import settings, given |
| 17 |
from hypothesis.database import InMemoryExampleDatabase |
| 18 |
from hypothesis.strategies import booleans |
| 19 |
import pytest |
| 20 |
|
| 21 |
DB = InMemoryExampleDatabase() |
| 22 |
|
| 23 |
|
| 24 |
@settings(database=DB) |
| 25 |
@given(booleans()) |
| 26 |
@pytest.mark.parametrize("hi", (1, 2, 3)) |
| 27 |
@pytest.mark.xfail() |
| 28 |
def test_dummy_for_parametrized_db_keys(hi, i): |
| 29 |
assert Fail # Test *must* fail for it to end up the database anyway |
| 30 |
|
| 31 |
|
| 32 |
def test_DB_keys_for_parametrized_test(): |
| 33 |
assert len(DB.data) == 3 |
| 34 |
""" |
| 35 |
|
| 36 |
|
| 37 |
def test_db_keys_for_parametrized_tests_are_unique(testdir): |
| 38 |
script = testdir.makepyfile(DB_KEY_TESTCASE) |
| 39 |
testdir.runpytest(script).assert_outcomes(xfailed=3, passed=1) |
| 40 |
|
| 41 |
|
| 42 |
@pytest.fixture(params=["a", "b"]) |
| 43 |
def fixt(request): |
| 44 |
return request.param |
| 45 |
|
| 46 |
|
| 47 |
class TestNoDifferingExecutorsHealthCheck: |
| 48 |
# Regression test for https://github.com/HypothesisWorks/hypothesis/issues/3733 |
| 49 |
|
| 50 |
@given(x=st.text()) |
| 51 |
@pytest.mark.parametrize("i", range(2)) |
| 52 |
def test_method(self, x, i): |
| 53 |
pass |
| 54 |
|
| 55 |
@settings(suppress_health_check=[HealthCheck.function_scoped_fixture]) |
| 56 |
@given(x=st.text()) |
| 57 |
def test_method_fixture(self, x, fixt): |
| 58 |
pass |