public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 1/2] python-utils-r1.eclass: Add eunittest helper
@ 2021-03-14 15:20 Michał Górny
  2021-03-14 15:20 ` [gentoo-dev] [PATCH 2/2] distutils-r1.eclass: Use eunittest, add dep on unittest-or-fail Michał Górny
  2021-03-14 16:42 ` [gentoo-dev] [PATCH 1/2] python-utils-r1.eclass: Add eunittest helper Wolfgang E. Sanyer
  0 siblings, 2 replies; 4+ messages in thread
From: Michał Górny @ 2021-03-14 15:20 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

Add an eunittest helper to wrap up the common 'python -m unittest
discover' calls, except that they are run via
dev-python/unittest-or-fail now.  This guarantees that if no tests are
discovered the test phase fails rather than silently ignoring
the problem.  This is especially helpful since it saves the developer
from having to inspect test phase logs.

Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 eclass/python-utils-r1.eclass | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 3036148b8383..d0bfb7819059 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -1299,5 +1299,28 @@ epytest() {
 	return ${?}
 }
 
+# @FUNCTION: eunittest
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Run unit tests using dev-python/unittest-or-fail, passing the standard
+# set of options, followed by user-specified options.
+#
+# This command dies on failure and respects nonfatal in EAPIs supporting
+# nonfatal die.
+eunittest() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	[[ -n ${EPYTHON} ]] || die "EPYTHON unset, invalid call context"
+
+	local die_args=()
+	[[ ${EAPI} != [45] ]] && die_args+=( -n )
+
+	set -- "${EPYTHON}" -m unittest_or_fail discover -v "${@}"
+
+	echo "${@}" >&2
+	"${@}" || die "${die_args[@]}" "Tests failed with ${EPYTHON}"
+	return ${?}
+}
+
 _PYTHON_UTILS_R1=1
 fi
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-dev] [PATCH 2/2] distutils-r1.eclass: Use eunittest, add dep on unittest-or-fail
  2021-03-14 15:20 [gentoo-dev] [PATCH 1/2] python-utils-r1.eclass: Add eunittest helper Michał Górny
@ 2021-03-14 15:20 ` Michał Górny
  2021-03-14 16:42 ` [gentoo-dev] [PATCH 1/2] python-utils-r1.eclass: Add eunittest helper Wolfgang E. Sanyer
  1 sibling, 0 replies; 4+ messages in thread
From: Michał Górny @ 2021-03-14 15:20 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

Switch to the new helper for running unittest-style tests.  Add a new
dependency on dev-python/unittest-or-fail.  Besides making the test
phase fail on missing tests, it also means that IUSE=test is now added
cnsistently with nose and pytest variants.

Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 eclass/distutils-r1.eclass | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index 655a33e0d208..b8b77103c0cb 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -426,6 +426,7 @@ distutils_enable_tests() {
 		setup.py)
 			;;
 		unittest)
+			test_pkg="dev-python/unittest-or-fail"
 			;;
 		*)
 			die "${FUNCNAME}: unsupported argument: ${1}"
@@ -830,7 +831,7 @@ distutils-r1_python_test() {
 			nonfatal esetup.py test --verbose
 			;;
 		unittest)
-			"${EPYTHON}" -m unittest discover -v
+			eunittest
 			;;
 		*)
 			die "Mis-synced test runner between ${FUNCNAME} and distutils_enable_testing"
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [gentoo-dev] [PATCH 1/2] python-utils-r1.eclass: Add eunittest helper
  2021-03-14 15:20 [gentoo-dev] [PATCH 1/2] python-utils-r1.eclass: Add eunittest helper Michał Górny
  2021-03-14 15:20 ` [gentoo-dev] [PATCH 2/2] distutils-r1.eclass: Use eunittest, add dep on unittest-or-fail Michał Górny
@ 2021-03-14 16:42 ` Wolfgang E. Sanyer
  2021-03-14 16:53   ` Zachery Huang
  1 sibling, 1 reply; 4+ messages in thread
From: Wolfgang E. Sanyer @ 2021-03-14 16:42 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 104 bytes --]

> [[ ${EAPI} != [45] ]] && die_args+=( -n )

Out of curiosity, why doesn't this check include EAPIs <4?

[-- Attachment #2: Type: text/html, Size: 375 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [gentoo-dev] [PATCH 1/2] python-utils-r1.eclass: Add eunittest helper
  2021-03-14 16:42 ` [gentoo-dev] [PATCH 1/2] python-utils-r1.eclass: Add eunittest helper Wolfgang E. Sanyer
@ 2021-03-14 16:53   ` Zachery Huang
  0 siblings, 0 replies; 4+ messages in thread
From: Zachery Huang @ 2021-03-14 16:53 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 337 bytes --]

IIUC, the check for 4 is redundant here. See[1]

[1] https://gitweb.gentoo.org/repo/gentoo.git/tree/eclass/python-utils-r1.eclass#n23
On Mar 15, 2021, 00:43 +0800, Wolfgang E. Sanyer <wolfgangesanyer@gmail.com>, wrote:
> > [[ ${EAPI} != [45] ]] && die_args+=( -n )
>
> Out of curiosity, why doesn't this check include EAPIs <4?

[-- Attachment #2: Type: text/html, Size: 1193 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-14 16:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-14 15:20 [gentoo-dev] [PATCH 1/2] python-utils-r1.eclass: Add eunittest helper Michał Górny
2021-03-14 15:20 ` [gentoo-dev] [PATCH 2/2] distutils-r1.eclass: Use eunittest, add dep on unittest-or-fail Michał Górny
2021-03-14 16:42 ` [gentoo-dev] [PATCH 1/2] python-utils-r1.eclass: Add eunittest helper Wolfgang E. Sanyer
2021-03-14 16:53   ` Zachery Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox