-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
# 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
There was a problem hiding this 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!
Motivation
Allow tests to run with
jujuVersion.has_secrets
both enabled and disabled. Move away fromunittest.TestCase
.Structure
Tests are largely unaltered, with few exceptions:
test_delete_password
got removed andtest_delete_existing_password_secrets
now handles both versions with and without secrets.test_update_certificate
got removed andtest_update_certificate_secrets
now handles both versions with and without secrets.test_migration_from_databag
andtest_migration_from_single_secret
got adapted in order to run only ifhas_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