From e7f769ed93b3c0d3c7c9205bcd6a5b039deda7f1 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Wed, 2 Mar 2022 22:18:15 +0530 Subject: [PATCH] pytest: Custom marker for GitHub Created custom marker for skipping test if GitHub issue/pull is open. Signed-off-by: Abhijeet Kasurde --- receptorctl/tests/conftest.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/receptorctl/tests/conftest.py b/receptorctl/tests/conftest.py index cebbb85da..4a5d23996 100644 --- a/receptorctl/tests/conftest.py +++ b/receptorctl/tests/conftest.py @@ -7,6 +7,7 @@ import time import json import yaml +import urllib.request from click.testing import CliRunner from lib import create_certificate @@ -389,3 +390,23 @@ def f_invoke_as_json(command, args: list = []): return result, json_output return f_invoke_as_json + + +def pytest_configure(config): + config.addinivalue_line( + "markers", + "github(): this mark skips the tests for the given open GitHub issues", + ) + + +def pytest_runtest_setup(item): + gh_markers = [mark.args[0] for mark in item.iter_markers(name="github")] + if gh_markers: + issue_url = gh_markers[0] + with urllib.request.urlopen(issue_url) as f: + try: + status = json.loads(f.read())["state"] + if status == "open": + pytest.skip("Test skipped because GitHub issue is open") + except (json.decoder.JSONDecodeError, IndexError): + pass