Skip to content

Commit

Permalink
pytest: Custom marker for GitHub
Browse files Browse the repository at this point in the history
Created custom marker for skipping test if GitHub issue/pull
is open.

Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde committed Mar 2, 2022
1 parent 3ecf655 commit e7f769e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions receptorctl/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import time
import json
import yaml
import urllib.request
from click.testing import CliRunner

from lib import create_certificate
Expand Down Expand Up @@ -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

0 comments on commit e7f769e

Please sign in to comment.