On 2010-12-28 20:34, Tres Seaver wrote:
> -----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:

I agree, but in this case TestBrowser is not something that is tested 
but a utility to help writing tests. It is similar to DummyRequest, 
DummyModel, etc. That is why I moved it out to testing.py as well.

Wichert.

-- 
Wichert Akkerman <wich...@wiggy.net>   It is simple to make things.
http://www.wiggy.net/                  It is hard to make things simple.
_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to