← Back to issue list

Initial tests from `charmcraft init` do not pass

View original Github issue

Metadata

Project
charmcraft
Number
#243
Type
issue
State
closed
Author
tomwardill
Labels
Created
Updated
Closed

Current evaluation

Superseded by PR #247, which updates the init workflow to resolve failing tests caused by invalid config.yaml generation.

Suggested action:

No scores available.

Issue body

If you create a new charm with `charmcraft init`, the tests will not pass out of the box. This appears to be because the `config.yaml` file exists, but does not contain any valid yaml (just comments). ``` tomwardill@microk8s-juju:~/work/harbor-charms/harbor-core$ ./run_tests test_action (tests.test_charm.TestCharm) ... ERROR test_action_fail (tests.test_charm.TestCharm) ... ERROR test_config_changed (tests.test_charm.TestCharm) ... ERROR ====================================================================== ERROR: test_action (tests.test_charm.TestCharm) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/tomwardill/work/harbor-charms/harbor-core/tests/test_charm.py", line 21, in test_action harness = Harness(HarborCoreCharm) File "/home/tomwardill/work/harbor-charms/harbor-core/venv/lib/python3.8/site-packages/ops/testing.py", line 92, in __init__ self._update_config(key_values=self._load_config_defaults(config)) File "/home/tomwardill/work/harbor-charms/harbor-core/venv/lib/python3.8/site-packages/ops/testing.py", line 277, in _load_config_defaults charm_config = charm_config.get('options', {}) AttributeError: 'NoneType' object has no attribute 'get' ====================================================================== ERROR: test_action_fail (tests.test_charm.TestCharm) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/tomwardill/work/harbor-charms/harbor-core/tests/test_charm.py", line 30, in test_action_fail harness = Harness(HarborCoreCharm) File "/home/tomwardill/work/harbor-charms/harbor-core/venv/lib/python3.8/site-packages/ops/testing.py", line 92, in __init__ self._update_config(key_values=self._load_config_defaults(config)) File "/home/tomwardill/work/harbor-charms/harbor-core/venv/lib/python3.8/site-packages/ops/testing.py", line 277, in _load_config_defaults charm_config = charm_config.get('options', {}) AttributeError: 'NoneType' object has no attribute 'get' ====================================================================== ERROR: test_config_changed (tests.test_charm.TestCharm) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/tomwardill/work/harbor-charms/harbor-core/tests/test_charm.py", line 13, in test_config_changed harness = Harness(HarborCoreCharm) File "/home/tomwardill/work/harbor-charms/harbor-core/venv/lib/python3.8/site-packages/ops/testing.py", line 92, in __init__ self._update_config(key_values=self._load_config_defaults(config)) File "/home/tomwardill/work/harbor-charms/harbor-core/venv/lib/python3.8/site-packages/ops/testing.py", line 277, in _load_config_defaults charm_config = charm_config.get('options', {}) AttributeError: 'NoneType' object has no attribute 'get' ---------------------------------------------------------------------- Ran 3 tests in 0.017s FAILED (errors=3) ``` Either removing `config.yaml` so it drops into the default in `_load_config_defaults`, or making it's contents represent an empty dictionary is enough to fix it.

Evaluation history

Date Model Scores Action Summary
qwen3.6-35b-a3b-mtp-q6 Superseded by PR #247, which updates the init workflow to resolve failing tests caused by invalid config.yaml generation.
qwen/qwen3.6-35b-a3b Closed as superseded by PR #247, which updates charmcraft init test generation to resolve the config.yaml parsing error and ensure tests pass out of the box.
qwen/qwen3.6-35b-a3b Superseded by PR #247, which resolves the failing tests caused by invalid config.yaml generation in charmcraft init.
qwen3.6-35b-a3b-mtp-q6 Resolved by PR #247, which overhauls init test generation to prevent invalid config.yaml from breaking tests.
qwen3.6-35b-a3b-mtp-q6 Superseded by PR #247, which updates the charmcraft init template to generate passing tests and correctly parse config.yaml.

Update history

No update history recorded yet.

Related issues

Issue Project State Summary Similarity
#238 `charmcraft init` creates broken charm charmcraft closed Superseded by PR #247, which overhauls charmcraft init and its tests to prevent broken charm generation from commented-out actions. The new implementation resolves the template and test failures.
82%
#91 First pass at 'charmcraft init' charmcraft merged Merged the initial 'charmcraft init' implementation. Approved by two reviewers, the PR adds 1087 lines across 24 files to scaffold charms. README.md, additional options, and interactive prompts require future updates.
71%