!15 spec: use pytest instead of nose

From: @yezengruan 
Reviewed-by: @imxcc 
Signed-off-by: @imxcc
This commit is contained in:
openeuler-ci-bot 2022-03-29 11:40:57 +00:00 committed by Gitee
commit 0e8365b82d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 483 additions and 3 deletions

View File

@ -0,0 +1,35 @@
From 991ecb5de8c8603747a294efa980ec45e4f589d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
Date: Thu, 12 Nov 2020 13:34:14 +0000
Subject: [PATCH] Avoid truncating python version number when running sanity
test
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The current code assumes the version number string will be only three
characters long, which fails with "3.10".
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
setup.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/setup.py b/setup.py
index 5336551..e564fd8 100755
--- a/setup.py
+++ b/setup.py
@@ -283,7 +283,9 @@ class my_test(Command):
if self.plat_name is None:
self.plat_name = get_platform()
- plat_specifier = ".%s-%s" % (self.plat_name, sys.version[0:3])
+ plat_specifier = ".%s-%d.%d" % (self.plat_name,
+ sys.version_info[0],
+ sys.version_info[1])
if hasattr(sys, 'gettotalrefcount'):
plat_specifier += '-pydebug'
--
2.27.0

View File

@ -0,0 +1,73 @@
From 1cab3de8bc544550bd13926141b3a9a01951f502 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
Date: Thu, 12 Nov 2020 13:30:23 +0000
Subject: [PATCH 5/6] Avoid use of thread function deprecated in 3.9
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
PyEval_ThreadsInitialized was deprecated in 3.9, with deletion targetted
for 3.11. Furthermore since 3.7 it is guaranteed that threads are always
initialized by Py_Initialize(), so checking it is redundant.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
typewrappers.h | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/typewrappers.h b/typewrappers.h
index fc923bf..b197d65 100644
--- a/typewrappers.h
+++ b/typewrappers.h
@@ -255,24 +255,44 @@ PyObject * libvirt_virDomainSnapshotPtrWrap(virDomainSnapshotPtr node);
# endif /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
#endif
-#define LIBVIRT_BEGIN_ALLOW_THREADS \
+#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 7
+# define LIBVIRT_BEGIN_ALLOW_THREADS \
LIBVIRT_STMT_START { \
PyThreadState *_save = NULL; \
if (PyEval_ThreadsInitialized()) \
_save = PyEval_SaveThread();
-#define LIBVIRT_END_ALLOW_THREADS \
+# define LIBVIRT_END_ALLOW_THREADS \
if (PyEval_ThreadsInitialized()) \
PyEval_RestoreThread(_save); \
} LIBVIRT_STMT_END
-#define LIBVIRT_ENSURE_THREAD_STATE \
+# define LIBVIRT_ENSURE_THREAD_STATE \
LIBVIRT_STMT_START { \
PyGILState_STATE _save = PyGILState_UNLOCKED; \
if (PyEval_ThreadsInitialized()) \
_save = PyGILState_Ensure();
-#define LIBVIRT_RELEASE_THREAD_STATE \
+# define LIBVIRT_RELEASE_THREAD_STATE \
if (PyEval_ThreadsInitialized()) \
PyGILState_Release(_save); \
} LIBVIRT_STMT_END
+
+#else
+
+# define LIBVIRT_BEGIN_ALLOW_THREADS \
+ LIBVIRT_STMT_START { \
+ PyThreadState *_save = PyEval_SaveThread();
+
+# define LIBVIRT_END_ALLOW_THREADS \
+ PyEval_RestoreThread(_save); \
+ } LIBVIRT_STMT_END
+
+# define LIBVIRT_ENSURE_THREAD_STATE \
+ LIBVIRT_STMT_START { \
+ PyGILState_STATE _save = PyGILState_Ensure();
+
+# define LIBVIRT_RELEASE_THREAD_STATE \
+ PyGILState_Release(_save); \
+ } LIBVIRT_STMT_END
+#endif
--
2.27.0

View File

@ -0,0 +1,115 @@
From ccbe311a4bcb123933499126278ba48aab36427a Mon Sep 17 00:00:00 2001
From: Cole Robinson <crobinso@redhat.com>
Date: Sun, 5 Jul 2020 12:51:45 -0400
Subject: [PATCH 4/6] Fix PY_SSIZE_T_CLEAN deprecation warning
Seen running on fedora 32:
DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats
ret = libvirtmod.virDomainLookupByUUID(self._o, uuid)
This comes from here: https://bugs.python.org/issue36381
See the section about PY_SSIZE_T_CLEAN here:
https://docs.python.org/3/c-api/arg.html#strings-and-buffers
Solution is to use Py_ssize_t instead of int for unpacked '#' values,
combined with defined PY_SSIZE_T_CLEAN before importing Python.h. The
latter turns these deprecation warnings into runtime segfaults though
if we missed an instance.
I verified the virt-manager's test suite works fine after this change
Signed-off-by: Cole Robinson <crobinso@redhat.com>
---
libvirt-override.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/libvirt-override.c b/libvirt-override.c
index 2b39ace..00efe7f 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -17,6 +17,7 @@
/* We want to see *_LAST enums. */
#define VIR_ENUM_SENTINELS
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
@@ -3040,7 +3041,7 @@ libvirt_virDomainLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
virConnectPtr conn;
PyObject *pyobj_conn;
unsigned char * uuid;
- int len;
+ Py_ssize_t len;
if (!PyArg_ParseTuple(args, (char *)"Oz#:virDomainLookupByUUID",
&pyobj_conn, &uuid, &len))
@@ -3283,7 +3284,7 @@ libvirt_virNetworkLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
virConnectPtr conn;
PyObject *pyobj_conn;
unsigned char * uuid;
- int len;
+ Py_ssize_t len;
if (!PyArg_ParseTuple(args, (char *)"Oz#:virNetworkLookupByUUID",
&pyobj_conn, &uuid, &len))
@@ -3992,7 +3993,7 @@ libvirt_virStoragePoolLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
virConnectPtr conn;
PyObject *pyobj_conn;
unsigned char * uuid;
- int len;
+ Py_ssize_t len;
if (!PyArg_ParseTuple(args, (char *)"Oz#:virStoragePoolLookupByUUID",
&pyobj_conn, &uuid, &len))
@@ -4233,7 +4234,7 @@ libvirt_virSecretLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
virConnectPtr conn;
PyObject *pyobj_conn;
unsigned char * uuid;
- int len;
+ Py_ssize_t len;
if (!PyArg_ParseTuple(args, (char *)"Oz#:virSecretLookupByUUID",
&pyobj_conn, &uuid, &len))
@@ -4393,7 +4394,7 @@ libvirt_virSecretSetValue(PyObject *self ATTRIBUTE_UNUSED,
virSecretPtr secret;
PyObject *pyobj_secret;
const char *value;
- int size;
+ Py_ssize_t size;
unsigned int flags;
if (!PyArg_ParseTuple(args, (char *)"Oz#I:virSecretSetValue", &pyobj_secret,
@@ -4402,8 +4403,8 @@ libvirt_virSecretSetValue(PyObject *self ATTRIBUTE_UNUSED,
secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
LIBVIRT_BEGIN_ALLOW_THREADS;
- c_retval = virSecretSetValue(secret, (const unsigned char *)value, size,
- flags);
+ c_retval = virSecretSetValue(secret, (const unsigned char *)value,
+ (size_t) size, flags);
LIBVIRT_END_ALLOW_THREADS;
return libvirt_intWrap(c_retval);
@@ -4471,7 +4472,7 @@ libvirt_virNWFilterLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
virConnectPtr conn;
PyObject *pyobj_conn;
unsigned char * uuid;
- int len;
+ Py_ssize_t len;
if (!PyArg_ParseTuple(args, (char *)"Oz#:virNWFilterLookupByUUID",
&pyobj_conn, &uuid, &len))
@@ -10247,7 +10248,7 @@ libvirt_virNetworkPortLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
virNetworkPtr net;
PyObject *pyobj_net;
unsigned char *uuid;
- int len;
+ Py_ssize_t len;
if (!PyArg_ParseTuple(args, (char *)"Oz#:virNetworkPortLookupByUUID",
&pyobj_net, &uuid, &len))
--
2.27.0

View File

@ -0,0 +1,95 @@
From d966561b118ce9fe159a9a47c3a120e8439004d0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
Date: Thu, 12 Nov 2020 14:31:54 +0000
Subject: [PATCH 6/6] Replace deprecated PyEval_CallObject with PyObject_Call
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The former is deprecated since Python 3.9, and the latter has existed
for all 3.x and probably before.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
libvirt-override.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/libvirt-override.c b/libvirt-override.c
index 00efe7f..d1f3ac0 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -1856,7 +1856,7 @@ libvirt_virErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx,
VIR_PY_TUPLE_SET_GOTO(info, 8, libvirt_intWrap((long)err->int2), cleanup);
/* TODO pass conn and dom if available */
- result = PyEval_CallObject(libvirt_virPythonErrorFuncHandler, list);
+ result = PyObject_Call(libvirt_virPythonErrorFuncHandler, list, NULL);
Py_XDECREF(result);
}
@@ -1961,7 +1961,7 @@ virConnectCredCallbackWrapper(virConnectCredentialPtr cred,
VIR_PY_TUPLE_SET_GOTO(list, 1, pycbdata, cleanup);
PyErr_Clear();
- pyret = PyEval_CallObject(pycb, list);
+ pyret = PyObject_Call(pycb, list, NULL);
if (PyErr_Occurred()) {
PyErr_Print();
goto cleanup;
@@ -5505,7 +5505,7 @@ libvirt_virEventAddHandleFunc(int fd,
VIR_PY_TUPLE_SET_GOTO(cb_args, 1, libvirt_virVoidPtrWrap(opaque), cleanup);
VIR_PY_TUPLE_SET_GOTO(cb_args, 2, libvirt_virFreeCallbackWrap(ff), cleanup);
- result = PyEval_CallObject(addHandleObj, pyobj_args);
+ result = PyObject_Call(addHandleObj, pyobj_args, NULL);
if (!result) {
PyErr_Print();
PyErr_Clear();
@@ -5538,7 +5538,7 @@ libvirt_virEventUpdateHandleFunc(int watch,
VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(watch), cleanup);
VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, libvirt_intWrap(event), cleanup);
- result = PyEval_CallObject(updateHandleObj, pyobj_args);
+ result = PyObject_Call(updateHandleObj, pyobj_args, NULL);
if (!result) {
PyErr_Print();
PyErr_Clear();
@@ -5566,7 +5566,7 @@ libvirt_virEventRemoveHandleFunc(int watch)
VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(watch), cleanup);
- result = PyEval_CallObject(removeHandleObj, pyobj_args);
+ result = PyObject_Call(removeHandleObj, pyobj_args, NULL);
if (result) {
retval = 0;
} else {
@@ -5623,7 +5623,7 @@ libvirt_virEventAddTimeoutFunc(int timeout,
VIR_PY_TUPLE_SET_GOTO(cb_args, 1, libvirt_virVoidPtrWrap(opaque), cleanup);
VIR_PY_TUPLE_SET_GOTO(cb_args, 2, libvirt_virFreeCallbackWrap(ff), cleanup);
- result = PyEval_CallObject(addTimeoutObj, pyobj_args);
+ result = PyObject_Call(addTimeoutObj, pyobj_args, NULL);
if (!result) {
PyErr_Print();
PyErr_Clear();
@@ -5654,7 +5654,7 @@ libvirt_virEventUpdateTimeoutFunc(int timer,
VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(timer), cleanup);
VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, libvirt_intWrap(timeout), cleanup);
- result = PyEval_CallObject(updateTimeoutObj, pyobj_args);
+ result = PyObject_Call(updateTimeoutObj, pyobj_args, NULL);
if (!result) {
PyErr_Print();
PyErr_Clear();
@@ -5681,7 +5681,7 @@ libvirt_virEventRemoveTimeoutFunc(int timer)
VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(timer), cleanup);
- result = PyEval_CallObject(removeTimeoutObj, pyobj_args);
+ result = PyObject_Call(removeTimeoutObj, pyobj_args, NULL);
if (result) {
retval = 0;
} else {
--
2.27.0

View File

@ -0,0 +1,29 @@
From b8dad684bbb693de70ebd9393f6f8fd1da310d85 Mon Sep 17 00:00:00 2001
From: Jonathon Jongsma <jjongsma@redhat.com>
Date: Tue, 21 Sep 2021 14:10:59 -0500
Subject: [PATCH 3/6] Update readme to mention pytest instead of nose
Commit a376a2ab switch from python-nose to python-pytest for tests, but
the README was not updated.
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
---
README | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README b/README
index 96082f0..e42afa5 100644
--- a/README
+++ b/README
@@ -21,7 +21,7 @@ or to install as non-root
python setup.py build
python setup.py install --user
-If python-nose is installed, you can test the package with
+If python-pytest is installed, you can test the package with
python setup.py test
--
2.27.0

View File

@ -3,13 +3,20 @@
Summary: The libvirt virtualization API python3 binding Summary: The libvirt virtualization API python3 binding
Name: libvirt-python Name: libvirt-python
Version: 6.2.0 Version: 6.2.0
Release: 1 Release: 3
Source0: http://libvirt.org/sources/python/%{name}-%{version}.tar.gz Source0: http://libvirt.org/sources/python/%{name}-%{version}.tar.gz
Patch0000: setup-use-pytest-instead-of-nose-to-run-the-test-sui.patch
Patch0001: spec-use-pytest-instead-of-nose.patch
Patch0002: Update-readme-to-mention-pytest-instead-of-nose.patch
Patch0003: Fix-PY_SSIZE_T_CLEAN-deprecation-warning.patch
Patch0004: Avoid-use-of-thread-function-deprecated-in-3.9.patch
Patch0005: Replace-deprecated-PyEval_CallObject-with-PyObject_C.patch
Patch0006: Avoid-truncating-python-version-number-when-running-.patch
Url: http://libvirt.org Url: http://libvirt.org
License: LGPLv2+ License: LGPLv2+
BuildRequires: libvirt-devel == %{version} BuildRequires: libvirt-devel == %{version}
BuildRequires: python3-devel BuildRequires: python3-devel
BuildRequires: python3-nose BuildRequires: python3-pytest
BuildRequires: python3-lxml BuildRequires: python3-lxml
BuildRequires: gcc BuildRequires: gcc
@ -38,7 +45,7 @@ supplied by the libvirt library to use the virtualization capabilities
of recent versions of Linux (and other OSes). of recent versions of Linux (and other OSes).
%prep %prep
%setup -q %autosetup -p1
# Unset execute bit for example scripts; it can introduce spurious # Unset execute bit for example scripts; it can introduce spurious
# RPM dependencies, like /usr/bin/python3 # RPM dependencies, like /usr/bin/python3
@ -69,6 +76,17 @@ find examples -type f -exec chmod 0644 \{\} \;
%{python3_sitearch}/*egg-info %{python3_sitearch}/*egg-info
%changelog %changelog
* Thu Mar 29 2022 yezengruan <yezengruan@huawei.com> - 6.2.0-3
- Avoid truncating python version number when running sanity test
* Tue Jan 11 2022 imxcc <xingchaochao@huawei.com> - 6.2.0-2
- setup: use pytest instead of nose to run the test suite
- spec: use pytest instead of nose
- Update readme to mention pytest instead of nose
- Fix PY_SSIZE_T_CLEAN deprecation warning
- Avoid use of thread function deprecated in 3.9
- Replace deprecated PyEval_CallObject with PyObject_Call
* Wed Apr 15 2020 Xu Yandong <xuyandong2@huawei.com> - 6.2.0-1 * Wed Apr 15 2020 Xu Yandong <xuyandong2@huawei.com> - 6.2.0-1
- Rebase to version 6.2.0. - Rebase to version 6.2.0.
* Fri Jul 19 2019 openEuler Buildteam <buildteam@openeuler.org> - 5.5.0-1 * Fri Jul 19 2019 openEuler Buildteam <buildteam@openeuler.org> - 5.5.0-1

View File

@ -0,0 +1,82 @@
From 8f41e98220749e64164a5c9346e9875af3489a1d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
Date: Tue, 6 Apr 2021 20:07:25 +0200
Subject: [PATCH 1/6] setup: use pytest instead of nose to run the test suite
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The software we use for running tests - nose - has been
deprecated in favor of nose2.
We don't use anything nose-specific, just unittest.TestCase,
which pytest can handle just fine.
Switch to using pytest, which we already use for libvirt-dbus.
Signed-off-by: Ján Tomko <jtomko@redhat.com>
---
setup.py | 16 ++++++++--------
tox.ini | 4 ++--
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/setup.py b/setup.py
index 56b6eea..ffb0e13 100755
--- a/setup.py
+++ b/setup.py
@@ -292,13 +292,13 @@ class my_test(Command):
self.build_platlib = os.path.join(self.build_base,
'lib' + plat_specifier)
- def find_nosetests_path(self):
+ def find_pytest_path(self):
binaries = [
- "nosetests-%d.%d" % (sys.version_info[0],
+ "pytest-%d.%d" % (sys.version_info[0],
sys.version_info[1]),
- "nosetests-%d" % (sys.version_info[0]),
- "nosetests%d" % (sys.version_info[0]),
- "nosetests",
+ "pytest-%d" % (sys.version_info[0]),
+ "pytest%d" % (sys.version_info[0]),
+ "pytest",
]
for binary in binaries:
@@ -306,7 +306,7 @@ class my_test(Command):
if path is not None:
return path
- raise Exception("Cannot find any nosetests binary")
+ raise Exception("Cannot find any pytest binary")
def run(self):
"""
@@ -320,8 +320,8 @@ class my_test(Command):
else:
os.environ["PYTHONPATH"] = self.build_platlib
self.spawn([sys.executable, "sanitytest.py", self.build_platlib, apis[0]])
- nose = self.find_nosetests_path()
- self.spawn([sys.executable, nose])
+ pytest = self.find_pytest_path()
+ self.spawn([sys.executable, pytest])
class my_clean(clean):
diff --git a/tox.ini b/tox.ini
index de683b9..24c96c2 100644
--- a/tox.ini
+++ b/tox.ini
@@ -4,7 +4,7 @@ envlist = py36,py37,py38
[testenv]
deps=
lxml
- nose
+ pytest
commands=
python sanitytest.py
- nosetests
+ pytest
--
2.27.0

View File

@ -0,0 +1,33 @@
From 2b91386845357615bdef36ea597bd1a25b12987e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
Date: Thu, 8 Apr 2021 16:20:46 +0200
Subject: [PATCH 2/6] spec: use pytest instead of nose
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Ján Tomko <jtomko@redhat.com>
---
libvirt-python.spec | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libvirt-python.spec b/libvirt-python.spec
index 676b696..5cb671f 100644
--- a/libvirt-python.spec
+++ b/libvirt-python.spec
@@ -22,10 +22,10 @@ License: LGPLv2+
BuildRequires: libvirt-devel == %{version}
BuildRequires: python3-devel
%if 0%{?rhel} == 7
-BuildRequires: python36-nose
+BuildRequires: python36-pytest
BuildRequires: python36-lxml
%else
-BuildRequires: python3-nose
+BuildRequires: python3-pytest
BuildRequires: python3-lxml
%endif
BuildRequires: gcc
--
2.27.0