Page MenuHomeSoftware Heritage

Migrate from nose to pytest and add tox.ini
ClosedPublic

Authored by anlambert on Oct 26 2018, 10:36 PM.

Details

Summary

Migrate swh-web tests from nose to pytest.

The good news is that thanks to pytest-django, we benefit from the same tests features
as when using the command $ python3 manage.py test: automatic migrations, in-memory
database, ... This greatly simplifies the tests setup.

Also add tox.ini and fix deprecation warnings printed by the latest pytest version
available on PyPI.

Related T1261
Related T1247

Diff Detail

Repository
rDWAPPS Web applications
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

tox build on jenkins currently fails as static assets have not been generated. The following command must be executed before running tox: $ npm install && npm run build-dev

sounds good.
I'll let other review though ;)

Update diff in order to run the Python unit tests without the generation of
static assets through webpack.

Jenkins build should be green after this update.

olasd added a subscriber: olasd.

Neat trick with the assets stuff! I can confirm that make test looks happy in my setup.

pytest.ini
4

Meh.

This revision is now accepted and ready to land.Oct 29 2018, 1:45 PM
anlambert added inline comments.
pytest.ini
4

For the record, this was to filter out a deprecation warnings in docutils:

.tox/py3/lib/python3.5/site-packages/swh/web/tests/common/test_templatetags.py::SWHTemplateTagsTest::test_safe_docstring_display
  /home/antoine/swh/swh-environment/swh-web/.tox/py3/lib/python3.5/site-packages/docutils/io.py:245: DeprecationWarning: 'U' mode is deprecated
    self.source = open(source_path, mode, **kwargs)

Fortunately, pytest enables to filter out some warnings in a per test basis through a decorator (https://docs.pytest.org/en/latest/warnings.html#pytest-mark-filterwarnings). So I will use it in the corresponding test instead of using a global warnings filter.

Small update: use @pytest.mark.filterwarnings decorator to filter out
a deprecation warning related to docutils in the corresponding test
instead of using a global warnings filter.

This revision was automatically updated to reflect the committed changes.