Skip to content

Commit

Permalink
Use pytest test name in results file name (#2849)
Browse files Browse the repository at this point in the history
* Use pytest test name in results file name
Allows parallel execution on the same design by not using the same results file name.
Hide some uninteresting traceback

Co-authored-by: Marlon James <marlon.james@gmail.com>
Co-authored-by: Colin Marquardt <cmarqu42@gmail.com>
  • Loading branch information
3 people committed Feb 4, 2022
1 parent d56b765 commit a0ca8e0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cocotb/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def test(
) -> PathLike:
"""Run a test."""

__tracebackhide__ = True # Hide the traceback when using pytest

if sim_dir is None:
self.sim_dir = self.build_dir
else:
Expand Down Expand Up @@ -186,10 +188,20 @@ def test(
else:
self.gui = bool(gui)

# When using pytest, use test name as result file name
pytest_current_test = os.environ.get("PYTEST_CURRENT_TEST", "")

if pytest_current_test:
results_xml_name = pytest_current_test.split(":")[-1].split(" ")[0] + ".results.xml"
else:
results_xml_name = "results.xml"

results_xml_file = os.getenv(
"COCOTB_RESULTS_FILE", os.path.join(self.build_dir, "results.xml")
"COCOTB_RESULTS_FILE", os.path.join(self.build_dir, results_xml_name)
)

self.env["COCOTB_RESULTS_FILE"] = results_xml_file

with suppress(OSError):
os.remove(results_xml_file)

Expand Down

0 comments on commit a0ca8e0

Please sign in to comment.