<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 10/03/2010 13:48, Michael Foord wrote:
<blockquote cite="mid:4B97A32C.4070409@voidspace.org.uk" type="cite">
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
[snip...]<br>
Additionally, if you define load_tests in a package file then it gets
passed the 'pattern' argument (the third argument that&nbsp; is normally
None when you define load_tests in test modules). It is then
responsible for continuing test discovery into the package itself. As
it gets passed the test loader this is easy. Here is a version of
load_tests that continues discovery:<br>
  <br>
def load_tests(loader, tests, pattern):<br>
&nbsp;&nbsp;&nbsp; if pattern is not None:<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this_dir = os.path.abspath(os.path.dirname(__file__))<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; # continue discovery from this directory with the same <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; # pattern<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; suite = loader.discover(this_dir, pattern)<br>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; # this line adds tests from this __init__.py to the <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; # the suite created from discovery<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; suite.addTests(tests)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return suite<br>
&nbsp;&nbsp;&nbsp; # just return default tests if we weren't loaded by test discovery<br>
&nbsp;&nbsp;&nbsp; return tests<br>
  <br>
Note - I need to check this works properly (it should!) but am on my
way out. Caveat emptor!<br>
</blockquote>
<br>
This recipe works fine - but you need to invoke test discovery with a
pattern that will match the package name rather than only look in
python modules. If you call your test package 'test_something' then the
following will invoke the package load_tests function:<br>
<br>
&nbsp;&nbsp;&nbsp; unit2 discover -p 'test_*'<br>
<br>
Michael<br>
<blockquote cite="mid:4B97A32C.4070409@voidspace.org.uk" type="cite"><br>
If you ignore the comments it's only 7 lines of code. If it works
properly I should make sure this recipe is in the docs.<br>
  <br>
All the best,
  <br>
  <br>
Michael
  <br>
  <br>
  <br>
  <blockquote cite="mid:20100309061210.GA20444@idyll.org" type="cite">
    <pre wrap="">--

Using setuptools' 'test_suite' argument:

 <a moz-do-not-send="true" class="moz-txt-link-freetext"
 href="http://github.com/ctb/SomePackage/tree/master/examples/setuptools-test_suite/">http://github.com/ctb/SomePackage/tree/master/examples/setuptools-test_suite/</a>

--

Using setuptools' 'test_loader' argument:

 <a moz-do-not-send="true" class="moz-txt-link-freetext"
 href="http://github.com/ctb/SomePackage/tree/master/examples/setuptools-test_loader/">http://github.com/ctb/SomePackage/tree/master/examples/setuptools-test_loader/</a>

--

Building a fake TestSuite-like object:

 <a moz-do-not-send="true" class="moz-txt-link-freetext"
 href="http://github.com/ctb/SomePackage/tree/master/examples/fake_suite/">http://github.com/ctb/SomePackage/tree/master/examples/fake_suite/</a>

--

I'm particularly intrigued by the idea of coming up with a standard that
specifies some API-level compatibility with the discover protocol as well as
unittest behavior, e.g.

   python -m unittest &lt;something&gt;

but I didn't get a chance to figure this out tonight.  Code welcome,
esp in the context of the last (fake_suite) example.

cheers,
--titus
  </pre>
  </blockquote>
  <br>
  <br>
  <pre class="moz-signature" cols="72">-- 
<a moz-do-not-send="true" class="moz-txt-link-freetext"
 href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext"
 href="http://www.voidspace.org.uk/blog">http://www.voidspace.org.uk/blog</a>

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (&#8221;BOGUS AGREEMENTS&#8221;) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.

  </pre>
  <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
testing-in-python mailing list
<a class="moz-txt-link-abbreviated" href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a>
<a class="moz-txt-link-freetext" href="http://lists.idyll.org/listinfo/testing-in-python">http://lists.idyll.org/listinfo/testing-in-python</a>
  </pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">-- 
<a class="moz-txt-link-freetext" href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a>
<a class="moz-txt-link-freetext" href="http://www.voidspace.org.uk/blog">http://www.voidspace.org.uk/blog</a>

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (&#8221;BOGUS AGREEMENTS&#8221;) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.

</pre>
</body>
</html>