Skip to content

Commit

Permalink
chore: Use caplog to verify log calls
Browse files Browse the repository at this point in the history
Logger asserts are error-prone, because they assert calls, not actual messages. The caplog fixture is Pytest-native way to test logs. This makes integration-level unit tests easier to add.

For the caplog fixture to work on Python 2.6 (RHEL 6), pytest_catchlog needs to be installed. On more recent version of python, the fixture is included in Pytest.

pytest_catchlog caused pidfile write tests to fail. The fixture itself calls os.getpid, interfering with the patch. Every log message makes a getpid call that is recorded in the patch. assert_not_called patches then stopped working.

Fixed by removing the os.getpid patch. The original function is safe to use. test_write_pidfile_not_called verifies several calls among which write_to_disk is the important one, not getpid.

Card IDs:

* CCT-774
* CCT-963
* CCT-1084

Signed-off-by: Štěpán Tomsa <[email protected]>
  • Loading branch information
Glutexo committed Dec 19, 2024
1 parent 1597f13 commit e50102a
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 131 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ jobs:
curl -L -O https://files.pythonhosted.org/packages/cb/85/8a1588a04172e0853352ecfe214264c65a62ab35374d9ad9c569cf94c2a3/python_gnupg-0.4.6-py2.py3-none-any.whl
curl -L -O https://files.pythonhosted.org/packages/e6/35/f187bdf23be87092bd0f1200d43d23076cee4d0dec109f195173fd3ebc79/mock-2.0.0-py2.py3-none-any.whl
curl -L -O https://files.pythonhosted.org/packages/f2/94/3af39d34be01a24a6e65433d19e107099374224905f1e0cc6bbe1fd22a2f/argparse-1.4.0-py2.py3-none-any.whl
curl -L -O https://files.pythonhosted.org/packages/86/84/6bd1384196a6871a9108157ec934a1e1ee0078582cd208b43352566a86dc/pytest_catchlog-1.2.2-py2.py3-none-any.whl
cd ${CUR_DIR}
mkdir ../collections_module
curl -L -o ./../collections_module/collections.py https://raw.githubusercontent.com/RedHatInsights/insights-core/5c8ca0f2fb3de45908e8d931d40758af34a7997a/.collections.py
Expand Down
Loading

0 comments on commit e50102a

Please sign in to comment.