<p dir="ltr"></p>
<p dir="ltr">On Sep 19, 2016 9:30 PM, "Mads Kiilerich" <<a href="mailto:mads@kiilerich.com">mads@kiilerich.com</a>> wrote:<br>
><br>
> On 09/19/2016 09:01 PM, Thomas De Schampheleire wrote:<br>
>><br>
>> # HG changeset patch<br>
>> # User Thomas De Schampheleire <<a href="mailto:thomas.de.schampheleire@gmail.com">thomas.de.schampheleire@gmail.com</a>><br>
>> # Date 1474227861 -7200<br>
>> #      Sun Sep 18 21:44:21 2016 +0200<br>
>> # Node ID 7e0969f34a4cff5788f4815c7e66c441158666fc<br>
>> # Parent  59639343672495cb89be54b98f1d6d3a4c44307c<br>
>> tests: add as little code as possible in __init__.py<br>
>><br>
>> kallithea/tests/__init__.py contains quite a lot of code, including the test<br>
>> base class TestController. This in itself may be considered bad practice.<br>
>><br>
>> Specifically, this poses a problem when using pytest 3.0+, in which asserts<br>
>> in some files are not automatically rewritten to give improved assert<br>
>> output. That problem can be fixed by explicitly registering such files for<br>
>> assertion rewriting, but that register call should be executed _before_ said<br>
>> files are imported. I.e. if the register call is in<br>
>> kallithea/tests/__init__.py, assert calls in __init__.py itself can not be<br>
>> rewritten.<br>
>><br>
>> Since the TestController base class does effectively contain asserts, and we<br>
>> do not want to execute the register call from somewhere outside the<br>
>> kallithea/tests directory, we need to move the TestController class to<br>
>> another file (kallithea/tests/base.py). The import of that file then needs<br>
>> to happen _after_ executing the register call.<br>
>><br>
>> While not strictly necessary to fix the mentioned pytest problem, we take<br>
>> the opportunity to fully clean __init__.py and move everything possible to<br>
>> the new kallithea/tests/base.py. While doing so, unnecessary imports are<br>
>> removed, and imports are ordered alphabetically. Explicit imports of symbols<br>
>> from modules that were already imported as a whole, are removed in favor of<br>
>> fully qualifying the references (e.g. tempfile._RandomNameSequence).<br>
><br>
><br>
> Thanks<br>
><br>
><br>
>> diff --git a/kallithea/tests/__init__.py b/kallithea/tests/__init__.py<br>
>> --- a/kallithea/tests/__init__.py<br>
>> +++ b/kallithea/tests/__init__.py<br>
>> @@ -22,41 +22,10 @@ setup-app`) and provides the base testin<br>
>>     Refer to docs/contributing.rst for details on running the test suite.<br>
>>   """<br>
>> -import os<br>
>> -import re<br>
>> -import time<br>
>> -import logging<br>
>> -import datetime<br>
>> -import hashlib<br>
>> -import tempfile<br>
>>   -from tempfile import _RandomNameSequence<br>
>> -<br>
>> -import pylons<br>
>> -import pylons.test<br>
>> -from pylons import config, url<br>
>> -from pylons.i18n.translation import _get_translator<br>
>> -from pylons.util import ContextObj<br>
>> -<br>
>> -from routes.util import URLGenerator<br>
>> -from webtest import TestApp<br>
>>   import pytest<br>
>>   -from kallithea.lib.compat import unittest<br>
>> -from kallithea import is_windows<br>
>> -from kallithea.model.db import Notification, User, UserNotification<br>
>> -from kallithea.model.meta import Session<br>
>> -from kallithea.lib.utils2 import safe_str<br>
>> -<br>
>> -<br>
>> -os.environ['TZ'] = 'UTC'<br>
>> -if not is_windows:<br>
>> -    time.tzset()<br>
>> -<br>
>> -log = logging.getLogger(__name__)<br>
>> -<br>
>> -skipif = pytest.mark.skipif<br>
>> -parametrize = pytest.mark.parametrize<br>
>> +from kallithea.tests.base import *<br>
><br>
><br>
> Would you have any objections to dropping this and just use kallithea.tests.base where it is needed?<br>
><br>
> Import * in general is one thing, but having it in a module definition can make it even harder to figure out what is going on.</p>
<p dir="ltr">Does that work with the override of __all__? That is the real reason to import this way. If there is a better way, yes please.<br>
</p>