Merge ~mertkirpici/juju-lint:topic/coverage into juju-lint:master

Proposed by Mert Kirpici
Status: Merged
Approved by: Martin Kalcok
Approved revision: fca2a52d8ef38b12e662f7dadd131d9448d0b951
Merged at revision: ce5d33a2b39e4a133eb6abbabc5105c1c9e0ea55
Proposed branch: ~mertkirpici/juju-lint:topic/coverage
Merge into: juju-lint:master
Diff against target: 83 lines (+24/-3)
3 files modified
pyproject.toml (+15/-0)
tests/unit/test_config.py (+7/-2)
tox.ini (+2/-1)
Reviewer Review Type Date Requested Status
Sudeep Bhandari Approve
🤖 prod-jenkaas-bootstack continuous-integration Approve
Ramesh Sattaru (community) Approve
Robert Gildein Approve
Review via email: mp+436243@code.launchpad.net

Commit message

Require full unit test coverage

Description of the change

This was missed during the snap template update, we expect %100 test coverage in this project.

This also revealed a sneaky bug in the process. When the jujulint.config.Config class got initialized it was using the sys.argv of the pytest process, causing a testing error and not being able to pass arguments to pytest.

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Robert Gildein (rgildein) wrote :

LGTM

Maybe we can use our templates [1] in juju-lint, not in this MP.

---
[1]: https://git.launchpad.net/bootstack-charms-spec/tree/source/snap-pytest

review: Approve
Revision history for this message
Ramesh Sattaru (rameshcan) :
review: Approve
Revision history for this message
Mert Kirpici (mertkirpici) wrote (last edit ):

> LGTM
>
> Maybe we can use our templates [1] in juju-lint, not in this MP.
>
> ---
> [1]: https://git.launchpad.net/bootstack-charms-spec/tree/source/snap-pytest

Hi there Robert, thanks for the review! This snap recently seems to have received the template update but the coverage relation sections in tox and pyproject.toml were missing. I assumed they were also missing in the bootstack templates. Turns out they're not. Maybe they were skipped due to the sys.argv bug I tried to explain in the description. Passing arguments to pytest in tox.ini was broken.

I am thinking of applying both your suggestions and align pyproject.toml and tox.ini posargs in this MP, I think it is a better solution rather than diverging more. What are your thoughts?

Revision history for this message
Robert Gildein (rgildein) wrote :

> Hi there Robert, thanks for the review! This snap recently seems to have
> received the template update but the coverage relation sections in tox and
> pyproject.toml were missing. I assumed they were also missing in the bootstack
> templates. Turns out they're not. Maybe they were skipped due to the sys.argv
> bug I tried to explain in the description. Passing arguments to pytest in
> tox.ini was broken.

Maybe it was related with tox 4.* issue? Not sure here.

> I am thinking of applying both your suggestions and align pyproject.toml and
> tox.ini posargs in this MP, I think it is a better solution rather than
> diverging more. What are your thoughts?

It's up to you, I'm trying to suggest templates everywhere, because it's easier
to work on multiple project with similar dev behavior and also using them in various
projects helps to improve them. I think that using separate MP is better, because
you can add/update more templates at once (recently we add .gitignore).

Also feel free to update our templates if it's needed. Recently I removed
`addopts` [1] from `juju-spell`, because it was more annoying than helpful.

---
[1]: https://git.launchpad.net/bootstack-charms-spec/tree/source/snap-pytest/pyproject.toml#n38

them also.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sudeep Bhandari (sudeephb) :
review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision ce5d33a2b39e4a133eb6abbabc5105c1c9e0ea55

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/pyproject.toml b/pyproject.toml
2index c58e8e6..789c704 100644
3--- a/pyproject.toml
4+++ b/pyproject.toml
5@@ -33,3 +33,18 @@ skip_glob = '''
6 | report
7 )/
8 '''
9+
10+[tool.coverage.run]
11+relative_files = true
12+source = ["jujulint"]
13+omit = ["tests/**", "docs/**", "lib/**", "snap/**", "build/**", "setup.py"]
14+
15+[tool.coverage.report]
16+fail_under = 100
17+show_missing = true
18+
19+[tool.coverage.html]
20+directory = "report"
21+
22+[tool.coverage.xml]
23+output = "report/coverage.xml"
24diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py
25index 1d9060d..71c2e40 100644
26--- a/tests/unit/test_config.py
27+++ b/tests/unit/test_config.py
28@@ -3,12 +3,14 @@
29
30 import os
31 import sys
32+from unittest.mock import patch
33
34 import yaml
35
36 from jujulint.config import Config
37
38-config_file = f"{Config().config_dir()}/config.yaml"
39+with patch.object(sys, "argv", ["juju-lint"]):
40+ config_file = f"{Config().config_dir()}/config.yaml"
41 builtin_open = open
42 builtin_isfile = os.path.isfile
43
44@@ -52,6 +54,7 @@ def patch_user_config(mocker):
45 mocker.patch("builtins.open", my_mock_open)
46
47
48+@patch.object(sys, "argv", ["juju-lint"])
49 def test_config_file(mocker):
50 """Tests if the config entries set in the .config/juju-lint/config.yaml are correctly applied.
51
52@@ -65,6 +68,7 @@ def test_config_file(mocker):
53 assert config[key].get() == expected_config[key]
54
55
56+@patch.object(sys, "argv", ["juju-lint"])
57 def test_default_config(mocker):
58 """Tests if the default values are correctly read from config_default.yaml."""
59 default_config = {
60@@ -96,7 +100,8 @@ def test_parser_options(mocker):
61 "output": {"folder": "cli/folder"},
62 "format": "json",
63 }
64- test_args = sys.argv + [
65+ test_args = [
66+ "juju-lint",
67 "-F",
68 cli_config["format"],
69 "-l",
70diff --git a/tox.ini b/tox.ini
71index 8aefb78..f6d4326 100644
72--- a/tox.ini
73+++ b/tox.ini
74@@ -48,7 +48,8 @@ commands =
75 deps = {[testenv:lint]deps}
76
77 [testenv:unit]
78-commands = pytest {toxinidir}/tests/unit
79+commands = pytest {toxinidir}/tests/unit \
80+ {posargs:-v --cov --cov-report=term-missing --cov-report=html --cov-report=xml}
81 deps =
82 -r {toxinidir}/requirements.txt
83 -r {toxinidir}/tests/unit/requirements.txt

Subscribers

People subscribed via source and target branches