Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DPE-2674] Convert test_charm.py to pytest style testing instead of unittest #425

Merged
merged 10 commits into from
Apr 8, 2024

Conversation

lucasgameiroborges
Copy link
Member

@lucasgameiroborges lucasgameiroborges commented Apr 3, 2024

Motivation

Allow tests to run with jujuVersion.has_secrets both enabled and disabled. Move away from unittest.TestCase.

Structure

Tests are largely unaltered, with few exceptions:

  • test_delete_password got removed and test_delete_existing_password_secrets now handles both versions with and without secrets.
  • test_update_certificate got removed and test_update_certificate_secrets now handles both versions with and without secrets.
  • test_migration_from_databag and test_migration_from_single_secret got adapted in order to run only if has_secrets == True since they test migration from databag to secrets.

Only two global pytest fixtures are used: harness and _has_secrets. Especific patches are kept inside their respective tests.

Testing

cd path/to/tests/
tox run -e unit

Copy link

codecov bot commented Apr 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.96%. Comparing base (00a1a35) to head (cf05809).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #425      +/-   ##
==========================================
- Coverage   81.08%   80.96%   -0.12%     
==========================================
  Files          10       10              
  Lines        2252     2259       +7     
  Branches      362      363       +1     
==========================================
+ Hits         1826     1829       +3     
- Misses        351      354       +3     
- Partials       75       76       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lucasgameiroborges lucasgameiroborges marked this pull request as ready for review April 4, 2024 20:38
Comment on lines +50 to +55
# This causes every test defined in this file to run 2 times, each with
# charm.JujuVersion.has_secrets set as True or as False
@pytest.fixture(params=[True, False], autouse=True)
def _has_secrets(request, monkeypatch):
monkeypatch.setattr("charm.JujuVersion.has_secrets", PropertyMock(return_value=request.param))
return request.param
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going forward we should change the other tests and move this in conftest, but it can happen in a follow up PR.

@dragomirp dragomirp self-requested a review April 5, 2024 10:23
Copy link
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, re: decorators => the final decision is up to Marcelo here.

Copy link
Member

@marceloneppel marceloneppel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, @lucasgameiroborges! I left some comments in the code. Please take a look and evaluate what makes sense and what doesn't. Thanks!

tests/unit/test_charm.py Show resolved Hide resolved
tests/unit/test_charm.py Show resolved Hide resolved
tests/unit/test_charm.py Outdated Show resolved Hide resolved
tests/unit/test_charm.py Outdated Show resolved Hide resolved
tests/unit/test_charm.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants