From 0c4294cac2b31b34173202c691c36c91d328449a Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Mon, 13 Apr 2020 17:59:26 +0200 Subject: [PATCH 1/9] Documentation indentation fixes --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 667b6c8..28aefdd 100644 --- a/README.md +++ b/README.md @@ -33,14 +33,14 @@ jobs: with: parallel: true - coveralls_finish: - needs: test - runs-on: ubuntu-latest - steps: - - name: Coveralls Finished - uses: AndreMiras/coveralls-python-action@develop - with: - parallel-finished: true + coveralls_finish: + needs: test + runs-on: ubuntu-latest + steps: + - name: Coveralls Finished + uses: AndreMiras/coveralls-python-action@develop + with: + parallel-finished: true ``` ## Configuration From 5eb72ef793fa8e417f5dfa2e6dae1c810bc578f4 Mon Sep 17 00:00:00 2001 From: Dan Foreman-Mackey Date: Thu, 24 Sep 2020 11:44:38 -0400 Subject: [PATCH 2/9] Update entrypoint.py --- src/entrypoint.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/entrypoint.py b/src/entrypoint.py index b2601ab..15474eb 100755 --- a/src/entrypoint.py +++ b/src/entrypoint.py @@ -121,8 +121,9 @@ def post_webhook(repo_token): log.debug(f'requests.post("{url}", json={json})') response = requests.post(url, json=json) response.raise_for_status() - log.debug(f"response.json(): {response.json()}") - assert response.json() == {"done": True}, response.json() + result = response.json() + log.debug(f"response.json(): {result}") + assert result.get("done", False), response.json() def str_to_bool(value): From 24dfe21d5ead79f9a61ace4fe208e6910c3b3556 Mon Sep 17 00:00:00 2001 From: Dan Foreman-Mackey Date: Thu, 24 Sep 2020 11:56:13 -0400 Subject: [PATCH 3/9] Update entrypoint.py --- src/entrypoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entrypoint.py b/src/entrypoint.py index 15474eb..76c38c0 100755 --- a/src/entrypoint.py +++ b/src/entrypoint.py @@ -123,7 +123,7 @@ def post_webhook(repo_token): response.raise_for_status() result = response.json() log.debug(f"response.json(): {result}") - assert result.get("done", False), response.json() + assert result.get("done", False), result def str_to_bool(value): From f10e25f1a5708d823d4db7e4d6ea32d9634d8c89 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 15 Nov 2020 18:43:14 +0100 Subject: [PATCH 4/9] :construction_worker: Fixes CI build Error was: ``` make: python3.8: Command not found python3.8 -m venv venv make: *** [venv] Error 127 Makefile:23: recipe for target 'venv' failed Error: Process completed with exit code 2. ``` Also fixes `isort` warnings, the error was: ``` UserWarning: W0501: The following deprecated CLI flags were used and ignored: --recursive ``` And updates `black` linting. --- .github/workflows/push.yml | 4 ++-- CHANGELOG.md | 7 +++---- Makefile | 4 ++-- src/entrypoint.py | 4 +--- tests/test_entrypoint.py | 8 ++------ 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 7c92d3b..1c901a4 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -6,10 +6,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v1 + - uses: actions/setup-python@v2 - name: Unit tests - run: make test + run: make test PYTHON_WITH_VERSION=python3 - name: Default arguments uses: ./ diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c48d9a..de5bc5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,12 @@ # Change Log -## [v20200413] +## [Unreleased] + - Fixes entrypoint assertion error ([dfm](https://github.com/dfm)), refs #5 +## [v20200413] - Made `github-token` parameter optional - ## [v20200412] - - Leverages `with` keyword to configure the action - Adds parallel support - Adds webhook support @@ -14,5 +14,4 @@ ## [v20200411] - - Initial release diff --git a/Makefile b/Makefile index 8c518b4..bfc378e 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ pytest: virtualenv test: pytest lint lint/isort: virtualenv - $(ISORT) --check-only --recursive --diff $(SOURCES) + $(ISORT) --check-only --diff $(SOURCES) lint/flake8: virtualenv $(FLAKE8) $(SOURCES) @@ -46,7 +46,7 @@ lint/black: virtualenv lint: lint/isort lint/flake8 lint/black format/isort: virtualenv - $(ISORT) --recursive $(SOURCES) + $(ISORT) $(SOURCES) format/black: virtualenv $(BLACK) $(SOURCES) diff --git a/src/entrypoint.py b/src/entrypoint.py index 76c38c0..9379e7a 100755 --- a/src/entrypoint.py +++ b/src/entrypoint.py @@ -105,9 +105,7 @@ def get_build_number(github_sha, github_ref): def post_webhook(repo_token): - """" - https://docs.coveralls.io/parallel-build-webhook - """ + """https://docs.coveralls.io/parallel-build-webhook""" url = "https://coveralls.io/webhook" build_num = get_build_number(get_github_sha(), get_github_ref()) # note this (undocumented) parameter is optional, but needed for using diff --git a/tests/test_entrypoint.py b/tests/test_entrypoint.py index 4eedeee..f83a0be 100644 --- a/tests/test_entrypoint.py +++ b/tests/test_entrypoint.py @@ -269,18 +269,14 @@ def test_str_to_bool(self, value, expected): """Possible recognised values.""" assert entrypoint.str_to_bool(value) is expected - @pytest.mark.parametrize( - "value", ["", "yesn't"], - ) + @pytest.mark.parametrize("value", ["", "yesn't"]) def test_str_to_bool_value_error(self, value): """Other unrecognised string values raise a `ValueError`.""" with pytest.raises(ValueError) as ex_info: entrypoint.str_to_bool(value) assert ex_info.value.args == (f"{value} is not a valid boolean value",) - @pytest.mark.parametrize( - "value", [None, 0], - ) + @pytest.mark.parametrize("value", [None, 0]) def test_str_to_bool_attribute_error(self, value): """Other unrecognised non-string values raise an `AttributeError`.""" with pytest.raises(AttributeError) as ex_info: From 3c62ca4de5d07e3abe92cba2f13e618827b11646 Mon Sep 17 00:00:00 2001 From: Johannes Wilm Date: Sun, 29 Nov 2020 02:37:40 +0100 Subject: [PATCH 5/9] :bug: fix for parallel mode, flag_name & base_path (#8) This adds two new options (flag_name and base_path) that work the same way as they do in the main coveralls action and it fixes the calculation of the reference that is being used in the parallel_finished call. --- README.md | 7 +++ action.yml | 10 +++++ src/entrypoint.py | 31 +++++++------ tests/test_entrypoint.py | 96 ++++++++++++---------------------------- 4 files changed, 64 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index 28aefdd..c386f99 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ jobs: uses: AndreMiras/coveralls-python-action@develop with: parallel: true + flag-name: Unit Test coveralls_finish: needs: test @@ -56,6 +57,12 @@ jobs: # Set to `true` for the last action when using `parallel: true`. # Default: false parallel-finished: '' + # A name to identify the current job. This is useful in combination with `parallel: true`. + # Default: false + flag-name: '' + # A sub-directory in which coverage was executed. + # Default: false + base-path: '' # Set to true to increase logger verbosity. # Default: false debug: '' diff --git a/action.yml b/action.yml index 09bde97..a2e0bfd 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,12 @@ inputs: parallel-finished: description: 'Set to true for the last action when using `parallel: true`.' default: false + base-path: + description: 'The name of a sub-directory in which the coverage files are to be found.' + default: false + flag-name: + description: 'A description of the current job used in connection with parallel.' + default: false debug: description: 'Set to `true` to increase logger verbosity.' default: false @@ -23,6 +29,10 @@ runs: args: - --github-token - ${{ inputs.github-token }} + - --base-path + - ${{ inputs.base-path }} + - --flag-name + - ${{ inputs.flag-name }} - --parallel - ${{ inputs.parallel }} - --parallel-finished diff --git a/src/entrypoint.py b/src/entrypoint.py index 9379e7a..585ca73 100755 --- a/src/entrypoint.py +++ b/src/entrypoint.py @@ -23,7 +23,7 @@ def set_failed(message): sys.exit(ExitCode.FAILURE) -def patch_os_environ(repo_token, parallel): +def patch_os_environ(repo_token, parallel, flag_name): """ Temporarily updates the environment variable to satisfy coveralls Python API. That is because the coveralls package API consumes mostly environment variables. @@ -31,11 +31,13 @@ def patch_os_environ(repo_token, parallel): # https://github.com/coveralls-clients/coveralls-python/blob/2.0.0/coveralls/api.py#L146 parallel = "true" if parallel else "" environ = {"COVERALLS_REPO_TOKEN": repo_token, "COVERALLS_PARALLEL": parallel} + if flag_name: + environ["COVERALLS_FLAG_NAME"] = flag_name log.debug(f"Patching os.environ with: {environ}") return mock.patch.dict("os.environ", environ) -def run_coveralls(repo_token, parallel=False): +def run_coveralls(repo_token, parallel=False, flag_name=False, base_path=False): """Submits job to coveralls.""" # note that coveralls.io "service_name" can either be: # - "github-actions" (local development?) @@ -44,9 +46,11 @@ def run_coveralls(repo_token, parallel=False): # (depending on where it's ran from?) service_names = ("github", "github-actions") result = None + if base_path and os.path.exists(base_path): + os.chdir(base_path) for service_name in service_names: log.info(f"Trying submitting coverage with service_name: {service_name}...") - with patch_os_environ(repo_token, parallel): + with patch_os_environ(repo_token, parallel, flag_name): coveralls = Coveralls(service_name=service_name) try: result = coveralls.wear() @@ -84,6 +88,11 @@ def get_github_repository(): return os.environ.get("GITHUB_REPOSITORY") +def get_github_run_id(): + """e.g. 88748489334""" + return os.environ.get("GITHUB_RUN_ID") + + def get_pull_request_number(github_ref): """ >>> get_pull_request_number("refs/pull//merge") @@ -96,18 +105,10 @@ def is_pull_request(github_ref): return github_ref and github_ref.startswith("refs/pull/") -def get_build_number(github_sha, github_ref): - build_number = github_sha - if is_pull_request(github_ref): - pull_request_number = get_pull_request_number(github_ref) - build_number = f"{github_sha}-PR-{pull_request_number}" - return build_number - - def post_webhook(repo_token): """https://docs.coveralls.io/parallel-build-webhook""" url = "https://coveralls.io/webhook" - build_num = get_build_number(get_github_sha(), get_github_ref()) + build_num = get_github_run_id() # note this (undocumented) parameter is optional, but needed for using # `GITHUB_TOKEN` rather than `COVERALLS_REPO_TOKEN` repo_name = get_github_repository() @@ -137,6 +138,8 @@ def str_to_bool(value): def parse_args(): parser = argparse.ArgumentParser(description="Greetings") parser.add_argument("--github-token", nargs=1, required=True) + parser.add_argument("--flag-name", required=False, default=False) + parser.add_argument("--base-path", required=False, default=False) parser.add_argument( "--parallel", type=str_to_bool, nargs="?", const=True, default=False ) @@ -160,13 +163,15 @@ def main(): debug = args.debug repo_token = args.github_token[0] parallel = args.parallel + flag_name = args.flag_name + base_path = args.base_path parallel_finished = args.parallel_finished set_log_level(debug) log.debug(f"args: {args}") if parallel_finished: post_webhook(repo_token) else: - run_coveralls(repo_token, parallel) + run_coveralls(repo_token, parallel, flag_name, base_path) def try_main(): diff --git a/tests/test_entrypoint.py b/tests/test_entrypoint.py index f83a0be..f412cb5 100644 --- a/tests/test_entrypoint.py +++ b/tests/test_entrypoint.py @@ -44,7 +44,29 @@ def test_main(self): "entrypoint.run_coveralls" ) as m_run_coveralls: entrypoint.main() - assert m_run_coveralls.call_args_list == [mock.call("TOKEN", False)] + assert m_run_coveralls.call_args_list == [ + mock.call("TOKEN", False, False, False) + ] + + def test_main_flag_name(self): + argv = ["src/entrypoint.py", "--github-token", "TOKEN", "--flag-name", "FLAG"] + with patch_sys_argv(argv), mock.patch( + "entrypoint.run_coveralls" + ) as m_run_coveralls: + entrypoint.main() + assert m_run_coveralls.call_args_list == [ + mock.call("TOKEN", False, "FLAG", False) + ] + + def test_main_base_path(self): + argv = ["src/entrypoint.py", "--github-token", "TOKEN", "--base-path", "SRC"] + with patch_sys_argv(argv), mock.patch( + "entrypoint.run_coveralls" + ) as m_run_coveralls: + entrypoint.main() + assert m_run_coveralls.call_args_list == [ + mock.call("TOKEN", False, False, "SRC") + ] def test_main_parallel_finished(self): argv = ["src/entrypoint.py", "--github-token", "TOKEN", "--parallel-finished"] @@ -123,31 +145,11 @@ def test_run_coveralls_wear_error_twice(self): entrypoint.run_coveralls(repo_token="TOKEN") assert ex_info.value.args == (entrypoint.ExitCode.FAILURE,) - def test_get_build_number(self): - github_sha = "ffac537e6cbbf934b08745a378932722df287a53" - github_ref = "refs/pull/123/merge" - assert ( - entrypoint.get_build_number(github_sha, github_ref) - == "ffac537e6cbbf934b08745a378932722df287a53-PR-123" - ) - github_ref = "refs/heads/feature-branch-1" - assert ( - entrypoint.get_build_number(github_sha, github_ref) - == "ffac537e6cbbf934b08745a378932722df287a53" - ) - github_ref = None - assert ( - entrypoint.get_build_number(github_sha, github_ref) - == "ffac537e6cbbf934b08745a378932722df287a53" - ) - def test_post_webhook(self): """ Tests different uses cases: 1) default, no environment variable - 2) only `GITHUB_SHA` is set - 3) `GITHUB_REF` is a branch - 4) `GITHUB_REF` is a pull request + 2) `GITHUB_RUN_ID` is set """ repo_token = "TOKEN" json_response = {"done": True} @@ -165,50 +167,10 @@ def test_post_webhook(self): }, ) ] - # 2) only `GITHUB_SHA` is set - environ = { - "GITHUB_SHA": "ffac537e6cbbf934b08745a378932722df287a53", - } - with patch_requests_post(json_response) as m_post, patch_os_envirion(environ): - entrypoint.post_webhook(repo_token) - assert m_post.call_args_list == [ - mock.call( - "https://coveralls.io/webhook", - json={ - "repo_token": "TOKEN", - "repo_name": None, - "payload": { - "build_num": "ffac537e6cbbf934b08745a378932722df287a53", - "status": "done", - }, - }, - ) - ] - # 3) `GITHUB_REF` is a branch - environ = { - "GITHUB_SHA": "ffac537e6cbbf934b08745a378932722df287a53", - "GITHUB_REF": "refs/heads/feature-branch-1", - } - with patch_requests_post(json_response) as m_post, patch_os_envirion(environ): - entrypoint.post_webhook(repo_token) - assert m_post.call_args_list == [ - mock.call( - "https://coveralls.io/webhook", - json={ - "repo_token": "TOKEN", - "repo_name": None, - "payload": { - "build_num": "ffac537e6cbbf934b08745a378932722df287a53", - "status": "done", - }, - }, - ) - ] - # 4) `GITHUB_REF` is a pull request + # 2) `GITHUB_RUN_ID` and `GITHUB_REPOSITORY` are set environ = { - "GITHUB_SHA": "ffac537e6cbbf934b08745a378932722df287a53", - "GITHUB_REF": "refs/pull/123/merge", - "GITHUB_REPOSITORY": "octocat/Hello-World", + "GITHUB_RUN_ID": "845347868344", + "GITHUB_REPOSITORY": "AndreMiras/coveralls-python-action", } with patch_requests_post(json_response) as m_post, patch_os_envirion(environ): entrypoint.post_webhook(repo_token) @@ -217,9 +179,9 @@ def test_post_webhook(self): "https://coveralls.io/webhook", json={ "repo_token": "TOKEN", - "repo_name": "octocat/Hello-World", + "repo_name": "AndreMiras/coveralls-python-action", "payload": { - "build_num": "ffac537e6cbbf934b08745a378932722df287a53-PR-123", + "build_num": "845347868344", "status": "done", }, }, From bb2d6b0337691ee599531f0b138fcd74d6f2a3ce Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 29 Nov 2020 18:57:36 +0100 Subject: [PATCH 6/9] :loud_sound: Improves exception logging Makes sure stacktrace is being properly displayed on exception --- CHANGELOG.md | 2 ++ src/entrypoint.py | 7 ++++--- tests/test_entrypoint.py | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de5bc5d..74c4e83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [Unreleased] - Fixes entrypoint assertion error ([dfm](https://github.com/dfm)), refs #5 + - Fixes parallel mode ([johanneswilm](https://github.com/johanneswilm)), refs #8 + - Improves exception logging ## [v20200413] - Made `github-token` parameter optional diff --git a/src/entrypoint.py b/src/entrypoint.py index 585ca73..77efd96 100755 --- a/src/entrypoint.py +++ b/src/entrypoint.py @@ -19,7 +19,8 @@ class ExitCode(Enum): def set_failed(message): - log.error(message) + exc_info = message if isinstance(message, Exception) else None + log.error(message, exc_info=exc_info) sys.exit(ExitCode.FAILURE) @@ -57,9 +58,9 @@ def run_coveralls(repo_token, parallel=False, flag_name=False, base_path=False): break except CoverallsException as e: log.warning( - f"Failed submitting coverage with service_name: {service_name}" + f"Failed submitting coverage with service_name: {service_name}", + exc_info=e, ) - log.warning(e) if result is None: set_failed("Failed to submit coverage") log.debug(result) diff --git a/tests/test_entrypoint.py b/tests/test_entrypoint.py index f412cb5..5d9940f 100644 --- a/tests/test_entrypoint.py +++ b/tests/test_entrypoint.py @@ -121,8 +121,10 @@ def test_run_coveralls_wear_error_once(self): "Patching os.environ with: " "{'COVERALLS_REPO_TOKEN': 'TOKEN', 'COVERALLS_PARALLEL': ''}" ), - mock.call.warning("Failed submitting coverage with service_name: github"), - mock.call.warning(side_effect[0]), + mock.call.warning( + "Failed submitting coverage with service_name: github", + exc_info=side_effect[0], + ), mock.call.info( "Trying submitting coverage with service_name: github-actions..." ), From 50af55ed0bf1537fb4404f4ccc550befd17156bb Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 29 Nov 2020 19:48:57 +0100 Subject: [PATCH 7/9] :bug: Fixes service_job_id KeyError with coveralls==2.2.0 It seems like `coveralls==2.2.0` requires `service_job_id` to internally resubmit payload on 422 Unprocessable Entry error, refs: https://github.com/coveralls-clients/coveralls-python/pull/241/files#r532248047 --- CHANGELOG.md | 3 ++- src/entrypoint.py | 7 ++++++- tests/test_entrypoint.py | 43 +++++++++++++++++++++++++++++++++++----- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74c4e83..a191b5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,10 @@ # Change Log ## [Unreleased] + - Improves exception logging + - Fixes KeyError with `coveralls==2.2.0` - Fixes entrypoint assertion error ([dfm](https://github.com/dfm)), refs #5 - Fixes parallel mode ([johanneswilm](https://github.com/johanneswilm)), refs #8 - - Improves exception logging ## [v20200413] - Made `github-token` parameter optional diff --git a/src/entrypoint.py b/src/entrypoint.py index 77efd96..e35be4a 100755 --- a/src/entrypoint.py +++ b/src/entrypoint.py @@ -46,13 +46,18 @@ def run_coveralls(repo_token, parallel=False, flag_name=False, base_path=False): # for some reasons the "service_name" can be one or the other # (depending on where it's ran from?) service_names = ("github", "github-actions") + # sets `service_job_id` key so it exists, refs: + # https://github.com/coveralls-clients/coveralls-python/pull/241/files#r532248047 + service_job_id = None result = None if base_path and os.path.exists(base_path): os.chdir(base_path) for service_name in service_names: log.info(f"Trying submitting coverage with service_name: {service_name}...") with patch_os_environ(repo_token, parallel, flag_name): - coveralls = Coveralls(service_name=service_name) + coveralls = Coveralls( + service_name=service_name, service_job_id=service_job_id + ) try: result = coveralls.wear() break diff --git a/tests/test_entrypoint.py b/tests/test_entrypoint.py index 5d9940f..b535dc3 100644 --- a/tests/test_entrypoint.py +++ b/tests/test_entrypoint.py @@ -3,6 +3,7 @@ import pytest from coveralls.api import CoverallsException +from requests.models import Response import entrypoint @@ -23,11 +24,12 @@ def patch_sys_argv(argv): return mock.patch("sys.argv", argv) -def patch_requests_post(json_response=None): - new_mock = mock.Mock() - if json_response: - new_mock.return_value.json.return_value = json_response - return mock.patch("entrypoint.requests.post", new_mock) +def patch_requests_post(json_response=mock.Mock(), status_code=200): + response = Response() + response.status_code = status_code + response.json = lambda: json_response + m_post = mock.Mock(return_value=response) + return mock.patch("entrypoint.requests.post", m_post) class TestEntryPoint: @@ -147,6 +149,37 @@ def test_run_coveralls_wear_error_twice(self): entrypoint.run_coveralls(repo_token="TOKEN") assert ex_info.value.args == (entrypoint.ExitCode.FAILURE,) + def test_status_code_422(self): + """ + Makes sure the coveralls package retries on "422 Unprocessable Entry" error + rather than crashing while trying to access the `service_job_id` key, refs: + https://github.com/coveralls-clients/coveralls-python/pull/241/files#r532248047 + """ + status_code = 422 + with patch_requests_post(status_code=status_code) as m_post, pytest.raises( + SystemExit + ), patch_log() as m_log: + entrypoint.run_coveralls(repo_token="TOKEN") + # coveralls package will retry once per service we call it with + assert m_post.call_count == 4 + assert m_log.error.call_args_list == [ + mock.call("Failed to submit coverage", exc_info=None) + ] + assert m_log.warning.call_args_list == [ + mock.call( + "Failed submitting coverage with service_name: github", + exc_info=CoverallsException( + "Could not submit coverage: 422 Client Error: None for url: None" + ), + ), + mock.call( + "Failed submitting coverage with service_name: github-actions", + exc_info=CoverallsException( + "Could not submit coverage: 422 Client Error: None for url: None" + ), + ), + ] + def test_post_webhook(self): """ Tests different uses cases: From be358278593d5d1d489bdea4fe0affcd1f16b3da Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 29 Nov 2020 20:38:21 +0100 Subject: [PATCH 8/9] :recycle: Uses pytest.raises match shorthand --- tests/test_entrypoint.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/tests/test_entrypoint.py b/tests/test_entrypoint.py index b535dc3..fbeaae4 100644 --- a/tests/test_entrypoint.py +++ b/tests/test_entrypoint.py @@ -36,9 +36,10 @@ class TestEntryPoint: def test_main_no_token(self): """Argument `--github-token` is required.""" argv = ["src/entrypoint.py"] - with patch_sys_argv(argv), pytest.raises(SystemExit) as ex_info: + with patch_sys_argv(argv), pytest.raises( + SystemExit, match=f"{signal.SIGINT.value}" + ): entrypoint.main() - assert ex_info.value.args == (signal.SIGINT.value,) def test_main(self): argv = ["src/entrypoint.py", "--github-token", "TOKEN"] @@ -81,10 +82,9 @@ def test_main_parallel_finished(self): def test_try_main(self): with mock.patch( "entrypoint.main", side_effect=Exception - ) as m_main, pytest.raises(SystemExit) as ex_info: + ) as m_main, pytest.raises(SystemExit, match=f"{entrypoint.ExitCode.FAILURE}"): entrypoint.try_main() assert m_main.call_args_list == [mock.call()] - assert ex_info.value.args == (entrypoint.ExitCode.FAILURE,) def test_run_coveralls_github_token(self): """Simple case when Coveralls.wear() returns some results.""" @@ -144,10 +144,11 @@ def test_run_coveralls_wear_error_twice(self): CoverallsException("Error 1"), CoverallsException("Error 2"), ) - with patch_coveralls_wear() as m_wear, pytest.raises(SystemExit) as ex_info: + with patch_coveralls_wear() as m_wear, pytest.raises( + SystemExit, match=f"{entrypoint.ExitCode.FAILURE}" + ): m_wear.side_effect = side_effect entrypoint.run_coveralls(repo_token="TOKEN") - assert ex_info.value.args == (entrypoint.ExitCode.FAILURE,) def test_status_code_422(self): """ @@ -157,7 +158,7 @@ def test_status_code_422(self): """ status_code = 422 with patch_requests_post(status_code=status_code) as m_post, pytest.raises( - SystemExit + SystemExit, match=f"{entrypoint.ExitCode.FAILURE}" ), patch_log() as m_log: entrypoint.run_coveralls(repo_token="TOKEN") # coveralls package will retry once per service we call it with @@ -231,7 +232,7 @@ def test_post_webhook_error(self): environ = {} with patch_requests_post(json_response) as m_post, patch_os_envirion( environ - ), pytest.raises(AssertionError) as ex_info: + ), pytest.raises(AssertionError, match=f"{json_response}"): entrypoint.post_webhook(repo_token) assert m_post.call_args_list == [ mock.call( @@ -243,7 +244,6 @@ def test_post_webhook_error(self): }, ) ] - assert ex_info.value.args == (json_response,) @pytest.mark.parametrize( "value,expected", @@ -269,13 +269,11 @@ def test_str_to_bool(self, value, expected): @pytest.mark.parametrize("value", ["", "yesn't"]) def test_str_to_bool_value_error(self, value): """Other unrecognised string values raise a `ValueError`.""" - with pytest.raises(ValueError) as ex_info: + with pytest.raises(ValueError, match=f"{value} is not a valid boolean value"): entrypoint.str_to_bool(value) - assert ex_info.value.args == (f"{value} is not a valid boolean value",) @pytest.mark.parametrize("value", [None, 0]) def test_str_to_bool_attribute_error(self, value): """Other unrecognised non-string values raise an `AttributeError`.""" - with pytest.raises(AttributeError) as ex_info: + with pytest.raises(AttributeError, match=" object has no attribute 'lower'"): entrypoint.str_to_bool(value) - assert ex_info.value.args[0].endswith(" object has no attribute 'lower'") From 3329aa9dbf71c5a4749a7c99bebffe25f68dfd70 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Mon, 30 Nov 2020 13:34:51 +0100 Subject: [PATCH 9/9] :bookmark: v20201129 --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a191b5b..7637be4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,10 @@ # Change Log -## [Unreleased] +## [v20201129] - Improves exception logging - Fixes KeyError with `coveralls==2.2.0` - Fixes entrypoint assertion error ([dfm](https://github.com/dfm)), refs #5 - - Fixes parallel mode ([johanneswilm](https://github.com/johanneswilm)), refs #8 + - Fixes parallel mode ([johanneswilm](https://github.com/johanneswilm)), refs #7 and #8 ## [v20200413] - Made `github-token` parameter optional