Skip to content

Commit 132b3d0

Browse files
committed
refactor: simpler fun
1 parent 9264fb4 commit 132b3d0

File tree

1 file changed

+13
-11
lines changed
  • pytest_github_actions_annotate_failures

1 file changed

+13
-11
lines changed

pytest_github_actions_annotate_failures/plugin.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import print_function
22
import os
33
import pytest
4+
from collections import OrderedDict
45

56
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
67
def pytest_runtest_makereport(item, call):
@@ -44,18 +45,19 @@ def pytest_runtest_makereport(item, call):
4445

4546

4647
def _error_workflow_command(filesystempath, lineno, longrepr):
47-
if lineno is None:
48-
if longrepr is None:
49-
return '\n::error file={}'.format(filesystempath)
50-
else:
51-
longrepr = _escape(longrepr)
52-
return '\n::error file={}::{}'.format(filesystempath, longrepr)
48+
# Build collection of arguments. Ordering is strict for easy testing
49+
details_dict = OrderedDict()
50+
details_dict["file"] = filesystempath
51+
if lineno is not None:
52+
details_dict["line"] = lineno
53+
54+
details = ",".join("{}={}".format(k,v) for k,v in details_dict.items())
55+
56+
if longrepr is None:
57+
return '\n::error {}'.format(details)
5358
else:
54-
if longrepr is None:
55-
return '\n::error file={},line={}'.format(filesystempath, lineno)
56-
else:
57-
longrepr = _escape(longrepr)
58-
return '\n::error file={},line={}::{}'.format(filesystempath, lineno, longrepr)
59+
longrepr = _escape(longrepr)
60+
return '\n::error {}::{}'.format(details, longrepr)
5961

6062
def _escape(s):
6163
return s.replace('%', '%25').replace('\r', '%0D').replace('\n', '%0A')

0 commit comments

Comments
 (0)