Skip to content

Commit

Permalink
Jira fixture (#77)
Browse files Browse the repository at this point in the history
* Added basic jira fixture

* Added negative test

* Added description to readme
  • Loading branch information
liiight authored and lukas-bednar committed Jul 18, 2017
1 parent 77fbdfd commit 628f873
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
19 changes: 19 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ If you specify version, open issues will be **unresolved** only if they also aff
Even when the issue is closed, but your version was affected and it was not fixed for your version,
the issue will be considered **unresolved**.

Fixture usage
-------------

Besides a test marker, you can also use the added ``jira_issue`` fixture. This enables examining issue status mid test
and not just at the beginning of a test. The fixture return a boolean representing the state of the issue.
If the issue isn't found, or the jira plugin isn't loaded, it returns ``None``.

.. code:: python
NICE_ANIMALS = ["bird", "cat", "dog"]
def test_stuff(jira_issue):
animals = ["dog", "cat"]
for animal in animals:
if animal == "dog" and jira_issue("ORG-1382") is True:
print("Issue is still open, cannot check for dogs!")
continue
assert animal in NICE_ANIMALS
Requires
========

Expand Down
15 changes: 13 additions & 2 deletions pytest_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ def get_url(self):
class JiraMarkerReporter(object):
issue_re = r"([A-Z]+-[0-9]+)"

def __init__(self, strategy, docs, patern):
self.issue_pattern = re.compile(patern or self.issue_re)
def __init__(self, strategy, docs, pattern):
self.issue_pattern = re.compile(pattern or self.issue_re)
self.docs = docs
self.strategy = strategy.lower()

Expand Down Expand Up @@ -441,5 +441,16 @@ def pytest_configure(config):
resolved_statuses,
config.getvalue('jira_run_test_case'),
)
config._jira = jira_plugin
ok = config.pluginmanager.register(jira_plugin, "jira_plugin")
assert ok


@pytest.fixture
def jira_issue(request):
def wrapper_jira_issue(issue_id):
jira_plugin = getattr(request.config, '_jira')
if jira_plugin and jira_plugin.conn.is_connected():
return jira_plugin.is_issue_resolved(issue_id)

return wrapper_jira_issue
24 changes: 24 additions & 0 deletions tests/test_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,3 +704,27 @@ def test_fail():
""")
result = testdir.runpytest(*PLUGIN_ARGS)
assert_outcomes(result, passed=0, skipped=0, failed=0, error=0, xfailed=1)


def test_jira_fixture_run_positive(testdir):
testdir.makeconftest(CONFTEST)
testdir.makepyfile("""
import pytest
def test_pass(jira_issue):
assert not jira_issue("ORG-1382")
""")
result = testdir.runpytest(*PLUGIN_ARGS)
result.assert_outcomes(1, 0, 0)


def test_jira_fixture_run_negative(testdir):
testdir.makeconftest(CONFTEST)
testdir.makepyfile("""
import pytest
def test_pass(jira_issue):
assert jira_issue("ORG-1382")
""")
result = testdir.runpytest(*PLUGIN_ARGS)
result.assert_outcomes(0, 0, 1)

0 comments on commit 628f873

Please sign in to comment.