Skip to content

Commit da2fcbf

Browse files
authored
Merge pull request #45 from melexis/support-env
Support usage of environment variables inside robot documentation
2 parents 7b4d8c0 + 5f4ec49 commit da2fcbf

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/source/robot/example.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ${MESSAGE} Hello,
1111
*** Test Cases ***
1212
First Test
1313
[Documentation] Thorough and relatively lengthy documentation for the example test case that
14-
... logs ${MESSAGE} and ${NAD} and ${NAMES}.
14+
... logs ${MESSAGE} and ${NAD} and ${NAMES}. %{RUNTIME_VAR}
1515
[Tags] SWRQT-SOME_RQT ANOTHER-TAG SWRQT-OTHER_RQT SYSRQT-SOME_SYSTEM_RQT
1616
Log ${MESSAGE}
1717
Log ${NAD}

mlx/robot2rst/robot_parser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import re
23
from collections import namedtuple
34

@@ -66,6 +67,11 @@ def visit_TestCase(self, node):
6667
previous_token = token
6768
elif element_type == Token.TAGS:
6869
tags = [el.value for el in element.tokens if el.type == Token.ARGUMENT]
70+
71+
for var_name in re.findall(r'%\{(.+?)\}', doc):
72+
if var_name in os.environ:
73+
doc = doc.replace(f'%{{{var_name}}}', os.environ[var_name])
74+
6975
if self.evaluate_inclusion(tags):
7076
self.tests.append(self.TestAttributes(node.name, doc, tags))
7177

tox.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ commands =
4646
flake8 mlx setup.py
4747

4848
[testenv:sphinx2.4.5]
49+
setenv =
50+
RUNTIME_VAR = Test env variable
4951
deps=
5052
{[testenv]deps}
53+
setuptools<70
5154
jinja2 == 2.11.3
5255
markupsafe == 1.1.0
5356
docutils == 0.17
@@ -67,6 +70,8 @@ commands=
6770
mlx-warnings --config warnings_config.yml --command make -C doc html
6871

6972
[testenv:sphinx-latest]
73+
setenv =
74+
RUNTIME_VAR = Test env variable
7075
deps=
7176
{[testenv]deps}
7277
sphinx

0 commit comments

Comments
 (0)