Package: pytest-jira
IntroApytestplugin for JIRA integration.This plugin links tests with JIRA tickets. The plugin behaves similar to
thepytest-bugzillaplugin.The plugin does not close JIRA tickets, or create them. It just allows
you to link tests to existing tickets.Please feel free to contribute by forking and submitting pull requests
or by submitting feature requests or issues toissues.Test resultsIf the testunresolved…and therun=False, the test isskippedand therun=Trueor not set, the test is executed and based on it
the result isxpassed(e.g. unexpected pass) orxfailed(e.g. expected fail).
Interpretation ofxpassedresult depends on the py.test ini-filexfail_strictvalue,
i.e. withxfail_strict=truexpassedresults will fail the test suite.
More information about strict xfail available on the py.testdocIf the testresolved…the test is executed and based on it
the result ispassedorfailedIf theskipifparameter is provided …with valueFalseorcallable returning False-like valuejira marker line isignoredNOTE:You can set default value forrunparameter globally in config
file (optionrun_test_case) or from CLI--jira-do-not-run-test-case. Default value isrun=True.Marking testsYou can specify jira issue ID in docstring or in pytest.mark.jira decorator.By default the regular expression pattern for matching jira issue ID is[A-Z]+-[0-9]+,
it can be changed by--jira-issue-regex=REGEXor in a config file byjira_regex=REGEX.It’s also possible to change behavior if issue ID was not found
by setting--jira-marker-strategy=STRATEGYor in config file
asmarker_strategy=STRATEGY.Strategies for dealing with issue IDs that were not found:open- issue is considered as open (default)strict- raise an exceptionignore- issue id is ignoredwarn- write error message and ignoreIssue ID in decoratorIf you use decorator you can specify optional parametersrunandskipif.
Ifrunis false and issue is unresolved, the test will be skipped.
Ifskipifis is false jira marker line will be ignored.@pytest.mark.jira("ORG-1382",run=False)deftest_skip():# will be skipped if unresolvedassertFalse@pytest.mark.jira("ORG-1382")deftest_xfail():# will run and xfail if unresolvedassertFalse@pytest.mark.jira("ORG-1382",skipif=False)deftest_fail():# will run and fail as jira marker is ignoredassertFalseUsing lambda value for skipifYou can use lambda value forskipifparameter. Lambda function must take
issue JSON as input value and return boolean-like value. If any JIRA ID
gets False-like value marker for that issue will be ignored.@pytest.mark.jira("ORG-1382",skipif=lambdai:'my component'ini['components'])deftest_fail():# Test will run if 'my component' is not present in Jira issue's componentsassertFalse@pytest.mark.jira("ORG-1382","ORG-1412",skipif=lambdai:'to do'==i['status'])deftest_fail():# Test will run if either of JIRA issue's status differs from 'to do'assertFalseIssue ID in docstringYou can disable searching for issue ID in doc string by using--jira-disable-docs-searchparameter or bydocs_search=Falseinjira.cfg.deftest_xpass():# will run and xpass if unresolved"""issue: ORG-1382"""assertTrueStatus evaluationIssues are considered asresolvedif their status matchesresolved_statuses. By default it isResolvedorClosed.You can set your own custom resolved statuses on command line--jira-resolved-statuses, or in config file.If you specify components (in command line or jira.cfg), open issues will be consideredunresolvedonly if they are also open for at least one used component.If you specify version, open issues will beunresolvedonly if they also affects your version.
Even when the issue is closed, but your version was affected and it was not fixed for your version,
the issue will be consideredunresolved.If you specify fixed resolutions closed issues will beunresolvedif they do not also have aresolvedresolution.Fixture usageBesides a test marker, you can also use the addedjira_issuefixture. 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 returnsNone.NICE_ANIMALS=["bird","cat","dog"]deftest_stuff(jira_issue):animals=["dog","cat"]foranimalinanimals:ifanimal=="dog"andjira_issue("ORG-1382")isTrue:print("Issue is still open, cannot check for dogs!")continueassertanimalinNICE_ANIMALSRequirespytest >= 2.2.3requests >= 2.13.0sixretry>=0.9.2marshmallow>=3.2.0Installationpip install pytest_jiraUsageCreate ajira.cfgand put it at least in one of following places./etc/jira.cfg~/jira.cfgtests_root_dir/jira.cfgtests_test_dir/jira.cfgThe configuration file is loaded in that order mentioned above.
That means that first options from global configuration are loaded,
and might be overwritten by options from user’s home directory and
finally these might be overwritten by options from test’s root directory.See example bellow, you can use it as template, and update it according
to your needs.[DEFAULT]url=https://jira.atlassian.comusername=USERNAME (or blank for no authentication)password=PASSWORD (or blank for no authentication)token=TOKEN (either use token or username and password)# ssl_verification = True/False# version = foo-1.0# components = com1,second component,com3# strategy = [open|strict|warn|ignore] (dealing with not found issues)# docs_search = False (disable searching for issue id in docs)# issue_regex = REGEX (replace default `[A-Z]+-[0-9]+` regular expression)# resolved_statuses = comma separated list of statuses (closed, resolved)# resolved_resolutions = comma separated list of resolutions (done, fixed)# run_test_case = True (default value for 'run' parameter)# connection_error_strategy [strict|skip|ignore] Choose how to handle connection errors# return_jira_metadata = False (return Jira issue with metadata instead of boolean result)You can set the password and username fields by setting the PYTEST_JIRA_PASSWORD and PYTEST_JIRA_USERNAME
environment variables:exportPYTEST_JIRA_PASSWORD="FOO"exportPYTEST_JIRA_USERNAME="BAR"Configuration options can be overridden with command line options as well.
For all available command line options run following command.py.test--helpMark your tests with jira marker and issue id.@pytest.mark.jira('issue_id')You can put Jira ID into doc string of test case as well.Run py.test with jira option to enable the plugin.py.test--jiraTestsIn order to execute tests run$tox