esptest.testcase.unittest_case module

Glue between unittest.TestCase and XunitLogger.

This module has no dependency on pytest, so the base class works both under a plain unittest runner and under pytest.

esptest.testcase.unittest_case.get_case_result_from_outcome(test_case)[source]

Read pass/fail and a brief message for the current test method.

Meant to be called from tearDown and works with both runners, whose outcome objects differ:

  • unittest’s _Outcome keeps (test, exc_info) tuples on .errors, populated before tearDown runs (result.failures is only filled in afterwards, so it cannot be relied on here).

  • pytest keeps an ExceptionInfo list on _outcome.result._excinfo.

Returns (passed, message); message is empty when the case passed.

Parameters:

test_case (TestCase)

Return type:

Tuple[bool, str]

class esptest.testcase.unittest_case.EspTestCase(methodName='runTest')[source]

Bases: TestCase

A unittest.TestCase that streams results into an xUnit report.

Subclasses only need to set xunit_log_dir (and optionally target / config / xunit_suite_name) and write plain test_* methods. Each case is opened in setUp() and closed in tearDown() with the result derived from the runner outcome.

Under pytest, the bind_case_context fixture from esptest.pytest_plugin can inject target / config / xunit_log_dir onto the class automatically.

To fold several classes (or a whole pytest session) into a single report, assign a shared XunitLogger to xunit_logger before setUpClass() runs; the class then reuses that logger and does not close it (the owner is responsible for that).

target: str = 'unknown'

chip target, used in the default case_id()

config: str = 'Default'

build/config label, used in the default case_id()

xunit_log_dir: str = ''

directory the xUnit report (and per-case artifacts) are written under

xunit_suite_name: str = ''

xUnit suite name; defaults to the class name when empty

xunit_logger: XunitLogger | None = None

the logger; created in setUpClass(), or set externally to share one

case_id()[source]

xUnit/JUnit case id, <target>.<config>.<method_name> by default.

Return type:

str

classmethod setUpClass()[source]

Hook method for setting up class fixture before running tests in the class.

Return type:

None

classmethod tearDownClass()[source]

Hook method for deconstructing the class fixture after running all tests in the class.

Return type:

None

setUp()[source]

Hook method for setting up the test fixture before exercising it.

Return type:

None

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

Return type:

None