Skip to content

Commit

Permalink
Addressed review requests
Browse files Browse the repository at this point in the history
  • Loading branch information
rnemes committed Dec 13, 2024
1 parent a7c84cc commit a3faa50
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
2 changes: 1 addition & 1 deletion testplan/testing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ def collect_code_context(self) -> bool:
Collecting the file path, line number and code context of the assertions
if enabled.
"""
return getattr(self.cfg, "collect_code_context", False)
return self.cfg.collect_code_context


class ProcessRunnerTestConfig(TestConfig):
Expand Down
20 changes: 10 additions & 10 deletions testplan/testing/multitest/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,17 +1148,17 @@ def _run_testcase(
testcase_name=testcase.name, testcase_report=testcase_report
)

if self.cfg.testcase_report_target:
testcase = report_target(
func=testcase,
ref_func=getattr(
testsuite,
getattr(testcase, "_parametrization_template", ""),
None,
),
)

if getattr(self.cfg, "collect_code_context", False):
if self.cfg.testcase_report_target:
testcase = report_target(
func=testcase,
ref_func=getattr(
testsuite,
getattr(testcase, "_parametrization_template", ""),
None,
),
)

testcase = collect_code_context(func=testcase)

# specially handle skipped testcases
Expand Down
43 changes: 27 additions & 16 deletions tests/unit/testplan/testing/multitest/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,40 @@ def intermediary(result, description=None):
helper(result, description=description)


def test_group_no_marking():
"""
Tests, at result object level, when code context is not enabled.
"""
result = result_mod.Result()
result.equal(1, 1)
result_entry = result.entries.pop()
assert result_entry.line_no == None
assert result_entry.code_context == None


@result_mod.collect_code_context
def test_group_marking():
"""
Tests, at result object level, if marking works as expected.
"""
result = result_mod.Result()
result.equal(1, 1)

# Functions to test marking, with relative position of the assertions
functions = [
(test_group_marking, 6),
(helper, 1),
(intermediary, 2),
]
current_function = inspect.currentframe().f_code.co_name
for function, relative_position in functions:
# To prevent infinite recursion
if function.__name__ != current_function:
function(result)
result_entry = result.entries.pop()
code_context = get_code_context(function, relative_position)
assert result_entry.line_no == code_context[0]
assert result_entry.code_context == code_context[1]
result_entry = result.entries.pop()
code_context = get_code_context(test_group_marking, 6)
assert result_entry.line_no == code_context[0]
assert result_entry.code_context == code_context[1]

helper(result)
result_entry = result.entries.pop()
code_context = get_code_context(helper, 1)
assert result_entry.line_no == code_context[0]
assert result_entry.code_context == code_context[1]

intermediary(result)
result_entry = result.entries.pop()
code_context = get_code_context(intermediary, 2)
assert result_entry.line_no == code_context[0]
assert result_entry.code_context == code_context[1]


@testsuite
Expand Down

0 comments on commit a3faa50

Please sign in to comment.