port to pytest4

This commit is contained in:
maminjie 2021-01-11 19:01:52 +08:00
parent 713a39c4c0
commit 344e1d120e
4 changed files with 149 additions and 1 deletions

View File

@ -0,0 +1,53 @@
From fc3c3a92c9c53d923e1f9b1ab11d3362c73ac99d Mon Sep 17 00:00:00 2001
From: Balint Reczey <balint.reczey@canonical.com>
Date: Tue, 5 Nov 2019 16:49:25 +0100
Subject: [PATCH] Mark issue56 in a way that works wity pytest 4
reference: https://github.com/hamcrest/PyHamcrest/commit/fc3c3a92c9c53d923e1f9b1ab11d3362c73ac99d
---
pytest.ini | 2 ++
tests/hamcrest_unit_test/core/is_test.py | 2 +-
tests/hamcrest_unit_test/core/isinstanceof_test.py | 7 -------
3 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/pytest.ini b/pytest.ini
index 80c7b6a..55c7e5f 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -1,2 +1,4 @@
[pytest]
addopts = --cov hamcrest --cov-report term-missing --no-cov-on-fail
+markers =
+ issue56
diff --git a/tests/hamcrest_unit_test/core/is_test.py b/tests/hamcrest_unit_test/core/is_test.py
index 9205ddb..e0bd23d 100644
--- a/tests/hamcrest_unit_test/core/is_test.py
+++ b/tests/hamcrest_unit_test/core/is_test.py
@@ -39,7 +39,7 @@ def test_description_should_pass_through_matcher():
equal_matches = pytest.mark.parametrize('arg, identity, desc', (
('A', 'A', "'A'"),
(5 + 3, 8, "<8>"),
- pytest.mark.issue56((tuple(), (), "<()>")),
+ pytest.param(tuple(), (), "<()>", marks=pytest.mark.issue56),
))
equal_mismatches = pytest.mark.parametrize('arg, identity, desc', (
diff --git a/tests/hamcrest_unit_test/core/isinstanceof_test.py b/tests/hamcrest_unit_test/core/isinstanceof_test.py
index 862fd06..9f4608b 100644
--- a/tests/hamcrest_unit_test/core/isinstanceof_test.py
+++ b/tests/hamcrest_unit_test/core/isinstanceof_test.py
@@ -41,13 +41,6 @@ def test_matching_evaluation(arg, matcher):
def test_mismatching_evaluation(arg, matcher):
assert_does_not_match(matcher, arg, 'mismatched')
-@pytest.mark.parametrize('obj', (
- pytest.mark.issue56(()),
- 'str',
-))
-def test_matcher_creation_requires_type(obj):
- with pytest.raises(TypeError):
- instance_of(obj)
@pytest.mark.parametrize('desc, type', (
('an instance of int', int),

View File

@ -0,0 +1,59 @@
From 0170484ec60853dbbdbd4aa5f3ffff9517ee77ed Mon Sep 17 00:00:00 2001
From: Balint Reczey <balint.reczey@canonical.com>
Date: Tue, 5 Nov 2019 17:09:49 +0100
Subject: [PATCH] Drop Python 2-only tests breaking with pytest 4
reference: https://github.com/hamcrest/PyHamcrest/commit/0170484ec60853dbbdbd4aa5f3ffff9517ee77ed
---
tests/hamcrest_unit_test/core/is_test.py | 1 -
tests/hamcrest_unit_test/core/isinstanceof_test.py | 3 ---
tests/hamcrest_unit_test/matcher_test.py | 6 ------
3 files changed, 10 deletions(-)
diff --git a/tests/hamcrest_unit_test/core/is_test.py b/tests/hamcrest_unit_test/core/is_test.py
index e0bd23d..6c222b7 100644
--- a/tests/hamcrest_unit_test/core/is_test.py
+++ b/tests/hamcrest_unit_test/core/is_test.py
@@ -65,7 +65,6 @@ def test_description_uses_equal_to(arg, identity, desc):
@pytest.mark.parametrize('arg, identity', (
('A', str),
(1, int),
- only_py2((OldClass(), OldClass)),
))
def test_provides_instanceof_shortcut(arg, identity):
assert_matches(is_(identity), arg, "should match")
diff --git a/tests/hamcrest_unit_test/core/isinstanceof_test.py b/tests/hamcrest_unit_test/core/isinstanceof_test.py
index 9f4608b..a963d4f 100644
--- a/tests/hamcrest_unit_test/core/isinstanceof_test.py
+++ b/tests/hamcrest_unit_test/core/isinstanceof_test.py
@@ -26,7 +26,6 @@ class Child(Parent):
('foo', instance_of((str, int))),
(1, instance_of((int, str))),
('foo', instance_of((int, str))),
- only_py2((Parent(), instance_of(Parent))),
))
def test_matching_evaluation(arg, matcher):
assert_matches(matcher, arg, 'same class')
@@ -35,8 +34,6 @@ def test_matching_evaluation(arg, matcher):
@pytest.mark.parametrize('arg, matcher', (
('hi', instance_of(int)),
(None, instance_of(int)),
- only_py2(('not a parent', instance_of(Parent))),
- only_py2((None, instance_of(Parent))),
))
def test_mismatching_evaluation(arg, matcher):
assert_does_not_match(matcher, arg, 'mismatched')
diff --git a/tests/hamcrest_unit_test/matcher_test.py b/tests/hamcrest_unit_test/matcher_test.py
index ec40158..5bb14bf 100644
--- a/tests/hamcrest_unit_test/matcher_test.py
+++ b/tests/hamcrest_unit_test/matcher_test.py
@@ -77,9 +77,3 @@ def assert_describe_mismatch(expected, matcher, arg):
description = StringDescription()
matcher.describe_mismatch(arg, description)
assert expected == str(description)
-
-
-only_py3 = pytest.mark.skipif(sys.version_info < (3, ),
- reason="Only relevant in Python 3")
-only_py2 = pytest.mark.skipif(sys.version_info >= (3, ),
- reason="Only relevant in Python 2")

View File

@ -0,0 +1,30 @@
From a7ba2de9d3661c9a4489810669586be23f159d46 Mon Sep 17 00:00:00 2001
From: Simon Brunning <simon@brunningonline.net>
Date: Fri, 2 Nov 2018 09:50:20 +0000
Subject: [PATCH] Silence warnings from tests due to use of old
pytest.parameterize() signature.
reference: https://github.com/hamcrest/PyHamcrest/commit/a7ba2de9d3661c9a4489810669586be23f159d46
---
tests/hamcrest_unit_test/base_description_test.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tests/hamcrest_unit_test/base_description_test.py b/tests/hamcrest_unit_test/base_description_test.py
index 43d9bc9..ce76557 100644
--- a/tests/hamcrest_unit_test/base_description_test.py
+++ b/tests/hamcrest_unit_test/base_description_test.py
@@ -34,10 +34,10 @@ def test_append_text_delegates(desc):
@pytest.mark.parametrize('described, appended', (
(Described(), 'described'),
- pytest.mark.skipif(six.PY3, reason="py2 only")((six.u('unicode-py2'), "'unicode-py2'")),
- pytest.mark.skipif(six.PY3, reason="py2 only")((six.b('bytes-py2'), "'bytes-py2'")),
- pytest.mark.skipif(six.PY2, reason="py3 only")((six.u('unicode-py3'), "'unicode-py3'")),
- pytest.mark.skipif(six.PY2, reason="py3 only")((six.b('bytes-py3'), "<b'bytes-py3'>")),
+ pytest.param(six.u('unicode-py2'), "'unicode-py2'", marks=pytest.mark.skipif(six.PY3, reason="py2 only")),
+ pytest.param(six.b('bytes-py2'), "'bytes-py2'", marks=pytest.mark.skipif(six.PY3, reason="py2 only")),
+ pytest.param(six.u('unicode-py3'), "'unicode-py3'", marks=pytest.mark.skipif(six.PY2, reason="py3 only")),
+ pytest.param(six.b('bytes-py3'), "<b'bytes-py3'>", marks=pytest.mark.skipif(six.PY2, reason="py3 only")),
(six.u("\U0001F4A9"), six.u("'{0}'").format(six.u("\U0001F4A9"))),
))
def test_append_description_types(desc, described, appended):

View File

@ -1,11 +1,14 @@
Name: python-hamcrest
Version: 1.9.0
Release: 9
Release: 10
Summary: Hamcrest matchers for Python
License: BSD
URL: https://github.com/hamcrest/PyHamcrest
Source0: https://github.com/hamcrest/PyHamcrest/archive/V1.9.0/%{name}-1.9.0.tar.gz
Patch0001: 0001-Add-boolean-matchers.patch
Patch0002: 0002-Mark-issue56-in-a-way-that-works-wity-pytest4.patch
Patch0003: 0003-Drop-Python2-only-tests-breaking-with-pytest4.patch
Patch0004: 0004-Silence-warnings-from-tests-due-to-use-of-old-pytest.parameterize-signature.patch
BuildArch: noarch
%description
@ -47,6 +50,9 @@ PYTHONPATH=%{buildroot}%{python3_sitelib} py.test-%{python3_version} -v
%{python3_sitelib}/*
%changelog
* Fri Jan 08 2021 maminjie <maminjie1@huawei.com> - 1.9.0-10
- port to pytest4
* Wed Aug 05 2020 lingsheng <lingsheng@huawei.com> - 1.9.0-9
- Remove python2-hamcrest subpackage