python
config_error
ai_generated
true
FAILED tests/test_math.py::TestMath::test_add - AssertionError: 1 != 2 SubTest failed: test_add (test_math.TestMath.test_add) (i=1) AssertionError: 1 != 2
ID: python/pytest-subtests-unittest-count
80%Fix Rate
83%Confidence
0Evidence
2024-07-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.4 | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
unittest's subTest failures are reported by pytest but not always counted as separate failures in JUnit XML or exit codes when using older pytest versions or the pytest-subtests plugin without proper config.
generic中文
unittest 的 subTest 失败会被 pytest 报告,但在使用较旧 pytest 版本或未正确配置 pytest-subtests 插件时,不总是作为独立失败计入 JUnit XML 或退出码。
Workarounds
-
90% success
Install pytest-subtests: pip install pytest-subtests Subtest failures then appear as separate test outcomes in reports.
-
85% success
Upgrade pytest to >= 7.4 which improved subTest reporting and exit codes.
Dead Ends
Common approaches that don't work:
-
60% fail
Changes test IDs and reporting; may break CI dashboards that key on names.
-
80% fail
Reimplements subTest poorly; loses per-case reporting.