Project

General

Profile

Actions

Feature #2532

closed

Replace nose tests with pytest

Added by Bernhard Koschiček-Krombholz 8 months ago. Updated 8 months ago.

Status:
Closed
Priority:
Normal
Category:
Backend
Target version:
Start date:
2025-05-15
Estimated time:
8.00 h

Description

As discussed in the ACDH-CH Python meeting (PUG) we will replace nose tests with pytest, main reason being that nose tests are not very actively developed/supported anymore (e.g. nose will not be in the next Debian release).

Actions #1

Updated by Bernhard Koschiček-Krombholz 8 months ago

I tested pytest, it works fine.
Currently installed:

apt install python3-pytest python3-cov 

Created two files:
pytest-cov

[report]
precision = 2
omit =
    ../openatlas/api/import_scripts/*
    ../openatlas/views/vocabs.py
skip_covered = True
sort = Cover

pytest.ini

[pytest]
addopts = --cov=openatlas --cov=tests --cov-report=html --cov-report=term --cov-report=term-missing

And then run in from IDE or shell

cd ../openatlas/tests
pytest

Location of the coverage file: /openatlas/tests/htmlcov/index.html

Actions #3

Updated by Alexander Watzinger 8 months ago

  • Description updated (diff)
  • Status changed from Acknowledged to In Progress
  • Assignee set to Alexander Watzinger
  • Target version changed from 9.0.0 to 8.12.0

Thanks for this Bernhard! It works fine for me too. I did some documentation adaptions, will test it further and merge to develop once finished.

Actions #4

Updated by Alexander Watzinger 8 months ago

  • Subject changed from Replace python3-nose to Replace nose tests with pytest
  • Estimated time set to 8.00 h
Actions #5

Updated by Alexander Watzinger 8 months ago

After some testing I discovered some things which we can discuss:

  • The coverage isn't shown in the PyCharm output because of a known bug
    To fix it you can adapt the _jb_runner_tools.py file (in my case at /opt/pycharm-community/plugins/python-ce/helpers/pycharm/_jb_runner_tools.py) and move full_name = properties["name"] into the try catch block below.
  • I would prefer .pytest.ini over pytest.ini as the name of the config file. Both naming work but I like the config file being at the top.
  • I like using addopts = -ra -q --no-header in the ini file but but I'm not sure what the current addopts = -r w -W default does and what the motivation was.
    Most seem to be ignored by PyCharm anyway but are effecting command line usage when just executing pytest.
  • pytest-flask looked interesting but I couldn't find any advantages. Running tests in parallel would have been nice but would require a definite rewrite/restructure of our test (e.g. errors because of parallel database creations)
Actions #6

Updated by Bernhard Koschiček-Krombholz 8 months ago

  • I would prefer .pytest.ini over pytest.ini as the name of the config file. Both naming work but I like the config file being at the top.

As you like, but on the top sounds good.

  • I like using addopts = -ra -q --no-header in the ini file but but I'm not sure what the current addopts = -r w -W default does and what the motivation was.
    Most seem to be ignored by PyCharm anyway but are effecting command line usage when just executing pytest.

-r w Show a summary of warnings
-W default Show warnings that are normally hidden like Deprecation Warnings

I have used them, because I got the information that there are like 30 warnings, but not what warnings. But I didn't had much time to test everything through.

  • pytest-flask looked interesting but I couldn't find any advantages. Running tests in parallel would have been nice but would require a definite rewrite/restructure of our test (e.g. errors because of parallel database creations)

We can write a new ticket for this.

Actions #7

Updated by Alexander Watzinger 8 months ago

  • Status changed from In Progress to Closed

Thanks Bernhard for feedback. Changes vor pytest are in develop

Actions

Also available in: Atom PDF