You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NOTE: This code is based on the CPython unittest implementation, and
probably falls under the Python License.
The main things I wanted to accomplish with this were:
- Ensure that each test runs in its own `TestCase` instance
+ This makes it possible to move some per-test setup code from `setUp`
to `__init__`.
- Add `TestCase.run(test_result)`
+ In the CPython implementation, this method gives people a single
place to add custom logic that can run _after_ the tests have
completed, with access to the `unittest.TestResult` instance. This
is useful, as it allows people to only output debug information on
test failures.
While here I ended up making the following changes:
- Moved the test executing code into `TestCase` (and `_Outcome`), from
`_run_suite`.
+ As part of this, I also migrated the exception handling logic to use
`ucontextlib.contextmanager`
- Generate nicer error messages for failures in class setup/teardown
methods.
- Removed `__test_result__` and `__current_test__` hidden variables
- Migrate `TestCase.subTest` to use `ucontextlib.contextmanager`
+ This significantly simplifies the logic
- Make subtest failures output show inline similar to CPython.
Bugs fixed:
- Allow `skip` decorator to work on bare functions
- Stop `expectedFailure` decorator from masking non-assertion failures
- Show correct test name when wrapped with `expectedFailure` decorator
- Show correct test name when TestCase.runTest method exists
- Exceptions in setUp/tearDown should show as test failures
+ Previously they went up the stack, likely causing the process to
exit
- Exceptions in class setUp/tearDown should show as test failures
+ Previously they went up the stack, likely causing the process to
exit
- Don't invoke properties with names that start with `test`
- Non-AssertionError exceptions in subtests show up as "FAIL" instead of
"ERROR".
- Tests now execute in an explicit order
+ This makes it easier to write output tests for the unittest
framework. We _may_ want to explicitly shuffle this order so that
user's don't have cross-test dependencies.
Signed-off-by: Greg Darke <micropython@me.tsukasa.au>
0 commit comments