Skip to content

Commit 7447702

Browse files
committed
Allow specifying a run path
Fixes #19
1 parent 1529f56 commit 7447702

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@ jobs:
3434
3535
If your test is running in a Docker container, you have to install this plugin and manually set `GITHUB_ACTIONS` environment variable to `true` inside of Docker container. (For example, `docker-compose run --rm -e GITHUB_ACTIONS=true app -- pytest`)
3636

37+
If your tests are run from a subdirectory of the git repository, you have to set the `PYTEST_RUN_PATH` environment variable to the path of that directory relative to the repository root in order for GitHub to identify the files with errors correctly.
38+
3739
## Screenshot
3840
[![Image from Gyazo](https://i.gyazo.com/b578304465dd1b755ceb0e04692a57d9.png)](https://gyazo.com/b578304465dd1b755ceb0e04692a57d9)

plugin_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ def test_fail():
106106
)
107107

108108

109+
def test_annotation_fail_runpath(testdir):
110+
testdir.makepyfile(
111+
"""
112+
import pytest
113+
pytest_plugins = 'pytest_github_actions_annotate_failures'
114+
115+
def test_fail():
116+
assert 0
117+
"""
118+
)
119+
testdir.monkeypatch.setenv("GITHUB_ACTIONS", "true")
120+
testdir.monkeypatch.setenv("PYTEST_RUN_PATH", "some_path")
121+
result = testdir.runpytest_subprocess()
122+
result.stderr.fnmatch_lines(
123+
["::error file=some_path/test_annotation_fail_runpath.py,line=5::test_fail*assert 0*",]
124+
)
125+
126+
109127
def test_annotation_long(testdir):
110128
testdir.makepyfile(
111129
"""

pytest_github_actions_annotate_failures/plugin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def pytest_runtest_makereport(item, call):
3131
# collect information to be annotated
3232
filesystempath, lineno, _ = report.location
3333

34+
runpath = os.environ.get("PYTEST_RUN_PATH")
35+
if runpath:
36+
filesystempath = os.path.join(runpath, filesystempath)
37+
3438
# try to convert to absolute path in GitHub Actions
3539
workspace = os.environ.get("GITHUB_WORKSPACE")
3640
if workspace:

0 commit comments

Comments
 (0)