-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12/28/2010 01:39 PM, Wichert Akkerman wrote:
> On 2010-12-28 19:16, Chris McDonough wrote:
>> On Tue, 2010-12-28 at 15:36 +0100, Wichert Akkerman wrote:
>>> I recently refactored a package to move all test infrastructure out of
>>> tests/ to testing.py. This has one unfortunate side effect: on installs
>>> without test dependencies my app will now no longer start since the
>>> venusian scan aborts on test imports in testing.py. Is there a way block
>>> venusian from scanning testing.py?
>>
>> I'm afraid not.  But I'm not sure why it worked under tests/ but not
>> under testing.py, as Venusian scans everything?
> 
> That turned out to due to some other test refactoring I was doing at the 
> same time. It did surprise me to see that venusian was scanning tests; 
> somehow that feels undesirable. For reference this is the code that was 
> showing this problem:
> 
> from wsgi_intercept import zope_testbrowser
> 
> class TestBrowser(zope_testbrowser.WSGI_Browser):
>      """A test browser which does not check robots.txt."""
>      def __init__(self, *args, **kwargs):
>          zope_testbrowser.WSGI_Browser.__init__(self, *args, **kwargs)
>          self.mech_browser.set_handle_robots(False)
> 
> 
> since wsgi_intercept is only a test dependency this caused an 
> ImportError. As a workaround I hade to rewrite the code to look like this:
> 
> def TestBrowser():
>      from wsgi_intercept import zope_testbrowser
>      class TestBrowser(zope_testbrowser.WSGI_Browser):
>          """A test browser which does not check robots.txt."""
>          def __init__(self, *args, **kwargs):
>              zope_testbrowser.WSGI_Browser.__init__(self, *args, **kwargs)
>              self.mech_browser.set_handle_robots(False)
>      return TestBrowser()
> 
> this works, but it isn't very pretty.

I actually argue that moving imports out of module scope in testcase
modules is best practice:


http://palladion.com/home/tseaver/obzervationz/2008/unit_testing_notes-20080724#guideline-minimize-module-scope-dependencies


Tres.
- -- 
===================================================================
Tres Seaver          +1 540-429-0999          tsea...@palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0aO6sACgkQ+gerLs4ltQ5wmgCgnx0atuO2dwU1YJBJvNisz+17
05AAn3lhYtOsQkYYDLdy/DyjXYgdhAHE
=y+bZ
-----END PGP SIGNATURE-----
_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to