public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michal Gorny (mgorny)" <mgorny@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] gentoo commit in xml/htdocs/proj/en/Python/python-r1: policy-guide.xml
Date: Tue, 22 Jan 2013 17:45:21 +0000 (UTC)	[thread overview]
Message-ID: <20130122174521.7ECF92171E@flycatcher.gentoo.org> (raw)

mgorny      13/01/22 17:45:21

  Modified:             policy-guide.xml
  Log:
  Add a section describing handling tests.

Revision  Changes    Path
1.8                  xml/htdocs/proj/en/Python/python-r1/policy-guide.xml

file : http://sources.gentoo.org/viewvc.cgi/gentoo/xml/htdocs/proj/en/Python/python-r1/policy-guide.xml?rev=1.8&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo/xml/htdocs/proj/en/Python/python-r1/policy-guide.xml?rev=1.8&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo/xml/htdocs/proj/en/Python/python-r1/policy-guide.xml?r1=1.7&r2=1.8

Index: policy-guide.xml
===================================================================
RCS file: /var/cvsroot/gentoo/xml/htdocs/proj/en/Python/python-r1/policy-guide.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- policy-guide.xml	14 Jan 2013 14:07:10 -0000	1.7
+++ policy-guide.xml	22 Jan 2013 17:45:21 -0000	1.8
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
 
-<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/proj/en/Python/python-r1/policy-guide.xml,v 1.7 2013/01/14 14:07:10 mgorny Exp $ -->
+<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/proj/en/Python/python-r1/policy-guide.xml,v 1.8 2013/01/22 17:45:21 mgorny Exp $ -->
 
 <guide lang="en">
 <title>python-r1 Policy Guide</title>
@@ -333,6 +333,129 @@
 	</section>
 </chapter>
 
+<chapter id="Development_tips">
+	<title>Development tips</title>
+
+	<section id="dt_Running_tests_in_Python_packages">
+		<title>Running tests in Python packages</title>
+
+		<body>
+			<p>
+				If a Python package provides tests suitable for automated
+				testing, the ebuild shall run those tests
+				in the <c>python_test()</c> (or <c>src_test()</c>) phase.
+			</p>
+
+			<p>
+				There are a number of common solutions for running tests —
+				including built-in <c>unittest</c> module,
+				<c>dev-python/nose</c>, <c>dev-python/pytest</c>. Often
+				the solutions are compatible with one another, enough to be able
+				to run a test suite designed for one of the other tools.
+			</p>
+
+			<p>
+				There are two common rules when choosing the test runner:
+			</p>
+
+			<ol>
+				<li>
+					the test runner shall introduce the least possible number
+					of dependencies,
+				</li>
+
+				<li>
+					the test runner chosen by upstream ought be preferred.
+				</li>
+			</ol>
+
+			<p>
+				When in doubt, it is often useful to review the package's test
+				modules for imports. If a package belonging to a test suite
+				is imported, the runner for that test suite shall be used.
+				The common test suites are listed in the following table:
+			</p>
+
+			<table>
+				<tr>
+					<th>Gentoo package</th>
+					<th>Python package (module)</th>
+					<th>Test runner (executable)</th>
+				</tr>
+
+				<tr>
+					<ti><c>dev-python/logilab-common</c></ti>
+					<ti><c>logilab.common.test</c></ti>
+					<ti><c>pytest</c></ti>
+				</tr>
+
+				<tr>
+					<ti><c>dev-python/nose</c></ti>
+					<ti><c>nose</c></ti>
+					<ti><c>nosetests</c></ti>
+				</tr>
+
+				<tr>
+					<ti><c>dev-python/pytest</c></ti>
+					<ti><c>pytest</c> or <c>py</c></ti>
+					<ti><c>py.test</c></ti>
+				</tr>
+
+				<tr>
+					<ti>(built-in)</ti>
+					<ti><c>unittest</c></ti>
+					<ti><c>${PYTHON} -m unittest discover</c> (since Python
+						2.7/3.2)</ti>
+				</tr>
+
+				<tr>
+					<ti><c>dev-python/unittest2</c></ti>
+					<ti><c>unittest2</c></ti>
+					<ti><c>unit2.py discover</c></ti>
+				</tr>
+			</table>
+
+			<p>
+				If the package defines the <c>test</c> command
+				for <c>setup.py</c> and uses one of the fore-mentioned test
+				suites, the best solution is the one requiring the least
+				effort or smallest number of dependencies.
+			</p>
+
+			<p>
+				There are a number of packages which require the <c>unittest2</c>
+				module only in versions of Python 2 older than 2.7 and Python 3
+				older than 3.2. Those packages shall depend
+				on <c>virtual/python-unittest2</c>.
+			</p>
+
+			<p>
+				If a particular package requires <c>unittest2</c> for Python 2.7+
+				and 3.2+ only for setuptools discovery module, it is preferred
+				to depend on the virtual package along with a <c>python_test()</c>
+				function similar to the following snippet:
+			</p>
+
+			<pre caption='Test discovery using unittest and unittest2'>
+<ident>DEPEND</ident>="test? ( virtual/python-unittest2[<var>${PYTHON_USEDEP}</var>] )"
+
+python_test() {
+	<keyword>local</keyword> <ident>runner</ident>=( <var>"${PYTHON}"</var> -m unittest )
+	<keyword>if</keyword> [[ <var>${EPYTHON}</var> == python2.[56] || <var>${EPYTHON}</var> == python3.1 ]]; <keyword>then</keyword>
+		<ident>runner</ident>=( unit2.py )
+	<keyword>fi</keyword>
+
+	<var>"${runner[@]}"</var> discover <comment># ...</comment>
+}
+</pre>
+
+			<p>
+				The tests need to die on failure.
+			</p>
+		</body>
+	</section>
+</chapter>
+
 <chapter id="Project_specific_policies">
 	<title>Project-specific policies</title>
 





             reply	other threads:[~2013-01-22 17:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-22 17:45 Michal Gorny (mgorny) [this message]
  -- strict thread matches above, loose matches on Subject: below --
2013-08-08  7:27 [gentoo-commits] gentoo commit in xml/htdocs/proj/en/Python/python-r1: policy-guide.xml Michal Gorny (mgorny)
2013-02-17  0:24 Michal Gorny (mgorny)
2013-01-30 11:30 Michal Gorny (mgorny)
2013-01-14 14:07 Michal Gorny (mgorny)
2013-01-14  9:37 Michal Gorny (mgorny)
2013-01-03 15:23 Michal Gorny (mgorny)
2013-01-02 19:54 Michal Gorny (mgorny)
2012-12-26 14:59 Michal Gorny (mgorny)
2012-12-21 21:35 Michal Gorny (mgorny)
2012-12-20 19:31 Michal Gorny (mgorny)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130122174521.7ECF92171E@flycatcher.gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox