Changeset - 56de50d57ff0
[Not reviewed]
default
0 2 0
Thomas De Schampheleire - 6 years ago 2020-02-04 20:08:41
thomas.de_schampheleire@nokia.com
pytest: fix register_assert_rewrite call

Since a while, the test suite shows following warning:

kallithea/tests/__init__.py:29
/home/tdescham/repo/contrib/kallithea/kallithea-review/kallithea/tests/__init__.py:29: PytestAssertRewriteWarning: Module already imported so cannot be rewritten: kallithea.tests
pytest.register_assert_rewrite('kallithea.tests')

The problem can be fixed by moving the register_assert_rewrite call from
kallithea/tests/__init__.py to the root-level conftest.py, outside of the
'kallithea' module.
2 files changed with 7 insertions and 10 deletions:
0 comments (0 inline, 0 general)
conftest.py
Show inline comments
 
@@ -27,12 +27,19 @@ def pytest_ignore_collect(path):
 
@pytest.fixture()
 
def doctest_mock_ugettext(request):
 
    """Mock ugettext ('_') in the module using this fixture.
 

	
 
    Intended to be used for doctests.
 

	
 
    In a doctest, enable this fixture using:
 
        >>> getfixture('doctest_mock_ugettext')
 
    """
 
    m = __import__(request.module.__name__, globals(), locals(), [None], 0)
 
    with mock.patch.object(m, '_', lambda s: s):
 
        yield
 

	
 
if getattr(pytest, 'register_assert_rewrite', None):
 
    # make sure that all asserts under kallithea/tests benefit from advanced
 
    # assert reporting with pytest-3.0.0+, including api/api_base.py,
 
    # models/common.py etc.
 
    # See also: https://docs.pytest.org/en/latest/assert.html#advanced-assertion-introspection
 
    pytest.register_assert_rewrite('kallithea.tests')
kallithea/tests/__init__.py
Show inline comments
 
@@ -8,22 +8,12 @@
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
"""
 
Kallithea test package
 

	
 
Refer to docs/contributing.rst for details on running the test suite.
 
"""
 

	
 
import pytest
 

	
 

	
 
if getattr(pytest, 'register_assert_rewrite', None):
 
    # make sure that all asserts under kallithea/tests benefit from advanced
 
    # assert reporting with pytest-3.0.0+, including api/api_base.py,
 
    # models/common.py etc.
 
    # See also: https://docs.pytest.org/en/latest/assert.html#advanced-assertion-introspection
 
    pytest.register_assert_rewrite('kallithea.tests')
0 comments (0 inline, 0 general)