summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorHolger Kohr <ho.kohr@zoho.com>2020-01-25 20:28:00 +0100
committerBruno Oliveira <nicoddemus@gmail.com>2020-01-28 18:05:53 -0300
commit80d4dd6f0bf289194f540f4ab6d6cf96776b8072 (patch)
tree68a9f5afe045014e3dda023372806971b9232e67 /testing
parent18ac7e0b79bcc99694ad095ff33746d6968c3b5e (diff)
downloadpytest-80d4dd6f0bf289194f540f4ab6d6cf96776b8072.tar.gz
Replace `==` with `is` for comparison of cache keys
Closes #6497
Diffstat (limited to 'testing')
-rw-r--r--testing/python/fixtures.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/testing/python/fixtures.py b/testing/python/fixtures.py
index 8cfaae50d..c72437ed5 100644
--- a/testing/python/fixtures.py
+++ b/testing/python/fixtures.py
@@ -1102,6 +1102,38 @@ class TestFixtureUsages:
"*Fixture 'badscope' from test_invalid_scope.py got an unexpected scope value 'functions'"
)
+ @pytest.mark.parametrize("scope", ["function", "session"])
+ def test_parameters_without_eq_semantics(self, scope, testdir):
+ testdir.makepyfile(
+ """
+ class NoEq1: # fails on `a == b` statement
+ def __eq__(self, _):
+ raise RuntimeError
+
+ class NoEq2: # fails on `if a == b:` statement
+ def __eq__(self, _):
+ class NoBool:
+ def __bool__(self):
+ raise RuntimeError
+ return NoBool()
+
+ import pytest
+ @pytest.fixture(params=[NoEq1(), NoEq2()], scope={scope!r})
+ def no_eq(request):
+ return request.param
+
+ def test1(no_eq):
+ pass
+
+ def test2(no_eq):
+ pass
+ """.format(
+ scope=scope
+ )
+ )
+ result = testdir.runpytest()
+ result.stdout.fnmatch_lines(["*4 passed*"])
+
def test_funcarg_parametrized_and_used_twice(self, testdir):
testdir.makepyfile(
"""