Skip to content

Commit

Permalink
fix context resolve dead loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyifan committed Nov 6, 2023
1 parent b9680d4 commit 056b41c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
11 changes: 5 additions & 6 deletions testplan/common/entity/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,16 +742,15 @@ def filter_locals(cls, local_vars):
if key not in EXCLUDE and value is not None
}

def context_input(self) -> Dict[str, Any]:
def context_input(self, exclude: list = None) -> Dict[str, Any]:
"""All attr of self in a dict for context resolution"""
ctx = {}
exclude = exclude or []
for attr in dir(self):
if attr == "env":
ctx["env"] = self._env
elif attr:
ctx[attr] = getattr(self, attr)
if attr in exclude:
continue
ctx[attr] = getattr(self, attr)
return ctx
# return {attr: getattr(self, attr) for attr in dir(self)}


class RunnableStatus(EntityStatus):
Expand Down
24 changes: 15 additions & 9 deletions testplan/testing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,20 +543,24 @@ def __init__(self, **options):
self._resolved_bin = None # resolved binary path

@property
def stderr(self) -> str:
return os.path.join(self._runpath, "stderr")
def stderr(self) -> Optional[str]:
if self._runpath:
return os.path.join(self._runpath, "stderr")

@property
def stdout(self) -> str:
return os.path.join(self._runpath, "stdout")
def stdout(self) -> Optional[str]:
if self._runpath:
return os.path.join(self._runpath, "stdout")

@property
def timeout_log(self) -> str:
return os.path.join(self._runpath, "timeout.log")
def timeout_log(self) -> Optional[str]:
if self._runpath:
return os.path.join(self._runpath, "timeout.log")

@property
def report_path(self) -> str:
return os.path.join(self._runpath, "report.xml")
def report_path(self) -> Optional[str]:
if self._runpath:
return os.path.join(self._runpath, "report.xml")

@property
def resolved_bin(self) -> str:
Expand Down Expand Up @@ -726,7 +730,9 @@ def get_proc_env(self):
# override with user specified values
if isinstance(self.cfg.proc_env, dict):
proc_env = {
key.upper(): render(val, self.context_input())
key.upper(): render(
val, self.context_input(exclude=["test_context"])
)
for key, val in self.cfg.proc_env.items()
}
env.update(proc_env)
Expand Down
2 changes: 1 addition & 1 deletion testplan/testing/multitest/driver/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def env(self) -> Optional[Dict[str, str]]:
return self._env

if isinstance(self.cfg.env, dict):
ctx = self.context_input()
ctx = self.context_input(exclude=["env"])
self._env = {
key: expand(val, self.context, str) if is_context(val)
# allowing None val for child class use case
Expand Down
6 changes: 5 additions & 1 deletion tests/functional/testplan/testing/cpp/test_gtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ def test_gtest(mockplan, binary_dir, expected_report, report_status):
)
pytest.skip(msg)

mockplan.add(GTest(name="My GTest", binary=binary_path))
mockplan.add(
GTest(
name="My GTest", binary=binary_path, proc_env={"NAME": "{{name}}"}
)
)

assert mockplan.run().run is True

Expand Down

0 comments on commit 056b41c

Please sign in to comment.