Clean up test template, make test code self-explanatory
Metadata
Current evaluation
Charmcraft 4.0 template updates resolved the request: PR #1551 (commit daf5a5b9) migrated generated unit tests from unittest to pytest functions/fixtures and plain assertions.
Resolution: closed resolved
Reason: PR #1551, resolved by commit daf5a5b9, replaced the generated unittest-based tests with pytest-style functions, fixtures, and plain assertions. A maintainer later noted that the major template changes met these suggestions in the pending 4.0 release.
Evaluated by: mr-cal-bot
No scores available.
Issue body
### What needs to get done
- The generated test code needs to be rewritten in a way that makes it self-explanatory.
- Comments should be removed, each test function/member should get a docstring instead that explains the purpose of or motivation for the test.
- If it's okay to use Pytest we can replace all boilerplate `assertXxx` calls by simple `assert` implementations.
- Refactoring the test code to use only functions (instead of a test class) might make the code more readable.
### Why it needs to get done
Getting started with Juju Charms is quite painful, especially due to the tests that immediately break once you start changing the generated setup.
The primary defect of the tests is that they are not self-explanatory. This is explained easily. Python code that is well-written doesn't need comments, the [generated code](https://github.com/canonical/charmcraft/blob/main/charmcraft/templates/init-simple/tests/unit/test_charm.py.j2), however, is literally polluted by comments. Also, the test code is pretty verbose due to being implemented as a TestCase-based class.
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Charmcraft 4.0 template updates resolved the request: PR #1551 (commit daf5a5b9) migrated generated unit tests from unittest to pytest functions/fixtures and plain assertions. | |
| stealth/space-bunny-alpha | — | closed resolved | Generated charm tests were refactored in PR #1551 (commit daf5a5b9), replacing unittest boilerplate with pytest fixtures, plain assertions, and clearer test functions for Charmcraft 4.0. | |
| stealth/space-bunny-alpha | — | closed resolved | Closed after Charmcraft 4.0 template updates; PR #1551 (daf5a5b9) had already migrated generated tests to pytest fixtures and plain assertions. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Requested template cleanup to make generated tests self-explanatory. Closed as the changes were implemented by contributors and will be included in the upcoming 4.0 release. | |
| qwen/qwen3.6-35b-a3b | — | — | Addressed by major template updates in the upcoming 4.0 release. Changes implement pytest-style asserts, replace comments with docstrings, and refactor tests to functions, delivering the requested cleaner and self-explanatory generated test code. | |
| qwen/qwen3.6-35b-a3b | — | — | Superseded by major template updates in the pending 4.0 release. The generated tests will now use docstrings, pytest-style assertions, and function-based structures to improve readability and eliminate verbose boilerplate. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Closed. The team implemented major template updates that address the request for cleaner, self-explanatory test code, scheduled for the 4.0 release. |
Update history
No update history recorded yet.
Related work
-
Likely Fixed By:
canonical/charmcraft#1551
(confidence 99%)
Merged commit daf5a5b9 modernized the generated test template and addressed the reported boilerplate and readability issues.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #1540 fix: template integration tests | charmcraft | merged | Merged PR #1540 as commit f3f82031, updating integration-test templates to use charmcraft.yaml instead of metadata.yaml and completing the stalled change from #1468. | |
| #2365 Add test configuration templates for charmcraft | charmcraft | closed | Test init profiles delivered by merged PR #2401 (commit a7334d49), adding test-machine and test-kubernetes templates for `charmcraft init`; shipped in Charmcraft 4.0. | |
| #1212 POC charmcraft test command | charmcraft | closed | Prototype request was closed unimplemented; PR #1660 later delivered charmcraft test and Spread templates in commit 097a4e9a. | |
| #2364 Update charmcraft test to use the new testing infrastructure | charmcraft | closed | Fixed by merged PR charmcraft#2385 (commit b7730efc), replacing Charmcraft’s custom test command with craft-application’s upstream test infrastructure. |