Skip to content

Commit 1906fcd

Browse files
authored
Merge pull request #6 from utgwkk/enable-only-in-workflow
Enable only in workflow
2 parents 07187df + 431aeeb commit 1906fcd

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

plugin_test.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ def test_success():
1111
assert 1
1212
'''
1313
)
14-
result = testdir.runpytest()
14+
testdir.monkeypatch.setenv('GITHUB_ACTIONS', 'true')
15+
result = testdir.runpytest_subprocess()
1516
result.stdout.no_fnmatch_line(
1617
'::error file=test_annotation_succeed_no_output.py*',
1718
)
@@ -26,7 +27,8 @@ def test_fail():
2627
assert 0
2728
'''
2829
)
29-
result = testdir.runpytest()
30+
testdir.monkeypatch.setenv('GITHUB_ACTIONS', 'true')
31+
result = testdir.runpytest_subprocess()
3032
result.stdout.fnmatch_lines([
3133
'::error file=test_annotation_fail.py,line=4::def test_fail():*',
3234
])
@@ -42,7 +44,24 @@ def test_fail():
4244
assert 1
4345
'''
4446
)
45-
result = testdir.runpytest()
47+
testdir.monkeypatch.setenv('GITHUB_ACTIONS', 'true')
48+
result = testdir.runpytest_subprocess()
4649
result.stdout.fnmatch_lines([
4750
'::error file=test_annotation_exception.py,line=4::def test_fail():*',
4851
])
52+
53+
def test_annotation_fail_disabled_outside_workflow(testdir):
54+
testdir.makepyfile(
55+
'''
56+
import pytest
57+
pytest_plugins = 'pytest_github_actions_annotate_failures'
58+
59+
def test_fail():
60+
assert 0
61+
'''
62+
)
63+
testdir.monkeypatch.setenv('GITHUB_ACTIONS', '')
64+
result = testdir.runpytest_subprocess()
65+
result.stdout.no_fnmatch_line(
66+
'::error file=test_annotation_fail_disabled_outside_workflow.py*',
67+
)

pytest_github_actions_annotate_failures/plugin.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import os
22

33
def pytest_runtest_logreport(report):
4+
# enable only in a workflow of GitHub Actions
5+
# ref: https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
6+
if os.environ.get('GITHUB_ACTIONS') != 'true':
7+
return
8+
49
if report.outcome != 'failed':
510
return
611

0 commit comments

Comments
 (0)