Skip to content

Commit

Permalink
Addressed reviewer request and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rnemes committed Dec 10, 2024
1 parent c01e1b5 commit 844f645
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion testplan/testing/multitest/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ def _run_testcase(
),
)

if self.cfg.collect_code_context:
if getattr(self.cfg, "collect_code_context", False):
testcase = collect_code_context(func=testcase)

# specially handle skipped testcases
Expand Down
30 changes: 19 additions & 11 deletions testplan/testing/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ def __exit__(self, exc_type, exc_value, tb):
description=self.description,
)

with MOD_LOCK:
# TODO: see https://github.com/python/cpython/commit/85cf1d514b84dc9a4bcb40e20a12e1d82ff19f20
caller_frame = inspect.stack()[1]
if getattr(assertion_state, "collect_code_context", False):
with MOD_LOCK:
# TODO: see https://github.com/python/cpython/commit/85cf1d514b84dc9a4bcb40e20a12e1d82ff19f20
caller_frame = inspect.stack()[1]

exc_assertion.file_path = os.path.abspath(caller_frame[1])
exc_assertion.line_no = caller_frame[2]
exc_assertion.file_path = os.path.abspath(caller_frame[1])
exc_assertion.line_no = caller_frame[2]
exc_assertion.code_context = caller_frame.code_context[0].strip()

# We cannot use `bind_entry` here as this block will
# be run when an exception is raised
Expand Down Expand Up @@ -1383,10 +1385,13 @@ def __exit__(self, exc_type, exc_value, traceback):
return False
super().__exit__(exc_type, exc_value, traceback)

with MOD_LOCK:
# TODO: see https://github.com/python/cpython/commit/85cf1d514b84dc9a4bcb40e20a12e1d82ff19f20
# XXX: do we have concrete ideas about thread-safety here?
caller_frame = inspect.stack()[1]
if getattr(assertion_state, "collect_code_context", False):
with MOD_LOCK:
# TODO: see https://github.com/python/cpython/commit/85cf1d514b84dc9a4bcb40e20a12e1d82ff19f20
# XXX: do we have concrete ideas about thread-safety here?
caller_frame = inspect.stack()[1]
else:
caller_frame = None

assertion = assertions.LogfileMatch(
self.timeout,
Expand All @@ -1395,8 +1400,11 @@ def __exit__(self, exc_type, exc_value, traceback):
self.description,
self.category,
)
assertion.file_path = os.path.abspath(caller_frame[1])
assertion.line_no = caller_frame[2]

if caller_frame:
assertion.file_path = os.path.abspath(caller_frame[1])
assertion.line_no = caller_frame[2]
# assertion.code_context = caller_frame.code_context[0].strip()

stdout_registry.log_entry(
entry=assertion, stdout_style=self.result.stdout_style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def main():
module_info.original_report for module_info in TEST_SUITE_MODULES
],
actual_reports=_get_actual_reports(plan),
ignore=["file_path", "line_no", "machine_time", "utc_time"],
ignore=["file_path", "line_no", "machine_time", "utc_time", "code_context"],
)
assert plan.interactive.report.passed is False

Expand Down Expand Up @@ -491,7 +491,7 @@ def main():
module_info.updated_report for module_info in TEST_SUITE_MODULES
],
actual_reports=actual_reports,
ignore=["file_path", "line_no", "machine_time", "utc_time"],
ignore=["file_path", "line_no", "machine_time", "utc_time", "code_context"],
)

assert plan.interactive.report.passed is True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def test_top_level_tests():
"utc_time",
"file_path",
"line_no",
"code_context",
],
)[0]
is True
Expand Down Expand Up @@ -210,6 +211,7 @@ def test_top_level_tests():
"utc_time",
"file_path",
"line_no",
"code_context",
],
)[0]
is True
Expand All @@ -233,6 +235,7 @@ def test_top_level_tests():
"utc_time",
"file_path",
"line_no",
"code_context",
],
)[0]
is True
Expand Down

0 comments on commit 844f645

Please sign in to comment.