Package: pytest-github
Build StatusCoverage
StatusRequirements
StatusVersionLicenseSupported
Python VersionsPlugin for py.test that integrates with github using markers.
Integration allows tests to xfail (or skip) based on the status of
linked github issues.InstallationInstall the plugin usingpippipinstallpytest-githubUsageOnce installed, the followingpy.testcommand-line parameters are
available.py.test\[--github-cfg=GITHUB_CFG]\[--github-username=GITHUB_USERNAME]\[--github-token=GITHUB_TOKEN]\[--github-completed=GITHUB_COMPLETED]\[--github-summary]Next, create a configure file calledgithub.ymlthat contains
your GitHub username andpersonal api
token. A sample
file is included below.github:username:j.doetoken:XXXXXXXXXXXXXMarkerThe followingpy.testmarker is available:@pytest.mark.github(*args):GitHubissueintegrationThe marker can be used to influence the outcome of tests. See the
examples below for guidance.Example: xfailOften, when a test fails, one might file a GitHub issue to track the
resolution of the problem. Alternatively, you could use the built-inxfailmarker. This is wherepytest-githubcan be of use. To
avoid having to review known failures with each test run, and to avoid
always usingxfail, consider thegithubmarker to dynamically
influence the test outcome based on the state of the GitHub issue.The following example demonstrates using thegithubmarker to
influence the outcome of a known failing test.@pytest.mark.github('https://github.com/some/open/issues/1')deftest_will_xfail():assertFalseRunning this test withpy.testwill produce the following output:test.py::test_will_xfailxfailExample: Anticipating specific exceptions with the ‘raises’ keywordTo avoid masking additional failures that might be uncovered by a test
while a github issue is being resolved, you can restrict expected
failures to specific exceptions using theraiseskeyword argument:@pytest.mark.github('https://github.com/some/open/issues/1',raises=ZeroDivisionError)deftest_will_xfail():foo=1/0@pytest.mark.github('https://github.com/some/open/issues/1',raises=ValueError)deftest_will_fail():# This test has been marked with an open issue but it will still fail# because the exception raised is different from the one indicated by# the 'raises' keyword.foo=1/0Running this test withpy.testwill produce the following output:collected2itemscollected1githubissuestest.py::test_will_xfailxfailtest.py::test_will_failFAILEDExample: XPASSThe following example demonstrates a test that succeeds, despite being
associated with anopenGitHub issue.@pytest.mark.github('https://github.com/some/open/issues/1')deftest_will_xpass():assertTrueIn this example, theXPASSoutcome (a.k.a. unexpected pass) is used.test.py::test_will_xpass XPASSExample: PASSEDThe following example demonstrates a test that succeeds, while it is
associated with aclosedGitHub issue. When a test associated with a
GitHub@pytest.mark.github('https://github.com/some/closed/issues/2')deftest_will_pass():assertTrueIn this example, thePASSEDoutcome is used.test.py::test_will_pass PASSEDExample: FAILEDThe following example demonstrates a test that fails, while it is
associated with aclosedGitHub issue.@pytest.mark.github('https://github.com/some/closed/issues/2')deftest_will_fail():assertFalseIn this example, theFAILEDoutcome is used.test.py::test_will_fail FAILEDExample: SKIPPEDThe following example demonstrates a test that fails, while it is
associated with anopenGitHub issue.@pytest.mark.github('https://github.com/some/open/issues/1',skip=True)deftest_will_skip():assertFalseIn this example, theSKIPPEDoutcome is used.test.py::test_will_skip SKIPPEDIn this example, theSKIPPEDoutcome is used.test.py::test_will_skip SKIPPEDExample: IDSThe following example demonstrates a parametrize test that uses thegithubmarker to influence the outcome of a subset of the known
failing test.@pytest.mark.github('https://github.com/some/open/issues/1',ids=['even2','even4'])@pytest.mark.parametrize("count",[1,2,3,4],ids=["odd1","even2","odd3","even4"])deftest_will_xfail(count):assertcount%2Summary of GitHub markers and their associated testsThe--github-summaryoption lists all GitHub issues referenced by agithubmarker. The list is divided into two sections,Resolved IssuesandUnresolved Issues, where an issue is
considered resolved if it has one of theGITHUB_COMPLETEDlabels.
Beneath each issue is a listing of all tests that reference the issue.Sample output:Unresolved Issues
https://github.com/repo/open/issues/1
 - test_suite.py:test_foo
https://github.com/repo/open/issues/2
 - test_suite.py:test_bar

Resolved Issues
https://github.com/repo/open/issues/3
 - test_suite.py:test_baz
 - test_suite.py:test_bah