Skip to content

Commit

Permalink
Merge pull request #13 from chrismeyersfsu/feature-target_ids
Browse files Browse the repository at this point in the history
Feature target ids
  • Loading branch information
jlaska committed Jul 12, 2018
2 parents 6c46509 + 130cbd3 commit 2683d0d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ In this example, the ``SKIPPED`` outcome is used.
test.py::test_will_skip SKIPPED
```

In this example, the ``SKIPPED`` outcome is used.

```
test.py::test_will_skip SKIPPED
```

### Example: IDS

The following example demonstrates a parametrize test that uses the ``github`` marker to influence the outcome of a subset of the known failing test.

```python
@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"])
def test_will_xfail(count):
assert count % 2
```

### Summary of GitHub markers and their associated tests

The `--github-summary` option lists all GitHub issues referenced by a `github` marker. The list is divided into two sections, `Resolved Issues` and `Unresolved Issues`, where an issue is considered resolved if it has one of the `GITHUB_COMPLETED` labels. Beneath each issue is a listing of all tests that reference the issue.
Expand Down
18 changes: 18 additions & 0 deletions pytest_github/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,24 @@ def pytest_runtest_setup(self, item):
if 'github' not in item.keywords:
return

github_marker = item.get_marker('github')

'''
github marker may specify ids=['foo', 'bar']. By specifying ids, only
test cases that match those ids will be considered by github marker
logic.
'''
github_marker_ids = github_marker.kwargs.get('ids', [])
if github_marker_ids:
param_marker = item.get_marker('parametrize')
param_marker_ids = []
if param_marker:
param_marker_ids = param_marker.kwargs.get('ids', [])
current_test_id = item.callspec.id

if current_test_id not in github_marker_ids:
return

unresolved_issues = []
issue_urls = item.funcargs["github_issues"]
for issue_url in issue_urls:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_parametrize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
import pytest
import mock

from _pytest.main import EXIT_OK


@pytest.mark.usefixtures('monkeypatch_github3')
def test_xfail_particular_parametrize_test_ids(testdir, capsys):
src = """
import pytest
@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"])
def test_will_xfail(count):
assert count % 2
"""
result = testdir.inline_runsource(src, *[''])
stdout, stderr = capsys.readouterr()
assert result.ret == EXIT_OK


0 comments on commit 2683d0d

Please sign in to comment.