glances icon indicating copy to clipboard operation
glances copied to clipboard

Improve unittest

Open nicolargo opened this issue 1 year ago • 6 comments

  • [x] use PyTest as a default test framework (have a look on official site, migration can be done softly with https://docs.pytest.org/en/8.2.x/how-to/unittest.html)
  • [x] Split memory leak test in a specific file
  • [x] Create a performance test
  • [x] Improve tests by testing all the plugin/model.py methods
  • [ ] Add dummies tests for all plugins (for example sensors could not be tested in the CI because the CI containers do not expose any sensors)
  • [ ] https://github.com/nicolargo/glances/issues/2749
  • [ ] write tests using Gherkin (Cucumber / Behave): see example here: https://github.com/ritvik-shetty/BDD_DEMO/tree/main/bdd_test
  • [x] https://github.com/nicolargo/glances/issues/3044

nicolargo avatar May 07 '24 09:05 nicolargo

Improve tests by testing all the plugin/model.py methods done in Glances 4.0.0

nicolargo avatar May 09 '24 08:05 nicolargo

Pytest tesbed

Include existing unittest

./venv/bin/pip install pytest

ln -s unittest-core.py test_core.py

./venv/bin/pytest
.....................................                                                                          [100%]
37 passed in 20.43s

Also work with other unitest file:

ln -s unittest-restful.py test_restful.py

ln -s unittest-xmlrpc.py test_xmlrpc.py

./venv/bin/pytest
......................................................................                                         [100%]
70 passed in 31.61s

Add new Pytest tests

Example:

cat /home/nhe/dev/glances/glances/timer_test.py
from .timer import Timer
def test_timer():
    t = Timer(5)
    assert t is not None

./venv/bin/pytest
.                                                                                                              [100%]
1 passed in 0.09s

nicolargo avatar May 28 '24 17:05 nicolargo

This issue is stale because it has been open for 3 months with no activity.

github-actions[bot] avatar Sep 28 '24 01:09 github-actions[bot]

For PyTest migration (have a look to https://github.com/giampaolo/psutil/commit/42c7a241c1caf8d723dc360422db937d6036b40f)

nicolargo avatar Nov 04 '24 08:11 nicolargo

Some interesting read: https://www.agest.am/write-good-python-tests

nicolargo avatar Nov 19 '24 10:11 nicolargo

For integration test: https://www.docker.com/blog/running-testcontainers-tests-using-github-actions/

nicolargo avatar Apr 12 '25 15:04 nicolargo