| 1 |
"""Helper plugin for pytester; should not be loaded on its own.""" |
| 2 |
|
| 3 |
# This plugin contains assertions used by pytester. pytester cannot |
| 4 |
# contain them itself, since it is imported by the `pytest` module, |
| 5 |
# hence cannot be subject to assertion rewriting, which requires a |
| 6 |
# module to not be already imported. |
| 7 |
from __future__ import annotations |
| 8 |
|
| 9 |
from collections.abc import Sequence |
| 10 |
|
| 11 |
from _pytest.reports import CollectReport |
| 12 |
from _pytest.reports import TestReport |
| 13 |
|
| 14 |
|
| 15 |
def assertoutcome( |
| 16 |
outcomes: tuple[ |
| 17 |
Sequence[TestReport], |
| 18 |
Sequence[CollectReport | TestReport], |
| 19 |
Sequence[CollectReport | TestReport], |
| 20 |
], |
| 21 |
passed: int = 0, |
| 22 |
skipped: int = 0, |
| 23 |
failed: int = 0, |
| 24 |
) -> None: |
| 25 |
__tracebackhide__ = True |
| 26 |
|
| 27 |
realpassed, realskipped, realfailed = outcomes |
| 28 |
obtained = { |
| 29 |
"failed": len(realfailed), |
| 30 |
"passed": len(realpassed), |
| 31 |
"skipped": len(realskipped), |
| 32 |
} |
| 33 |
expected = {"failed": failed, "passed": passed, "skipped": skipped} |
| 34 |
assert obtained == expected, outcomes |
| 35 |
|
| 36 |
|
| 37 |
def assert_outcomes( |
| 38 |
outcomes: dict[str, int], |
| 39 |
passed: int = 0, |
| 40 |
skipped: int = 0, |
| 41 |
failed: int = 0, |
| 42 |
errors: int = 0, |
| 43 |
xpassed: int = 0, |
| 44 |
xfailed: int = 0, |
| 45 |
warnings: int | None = None, |
| 46 |
deselected: int | None = None, |
| 47 |
) -> None: |
| 48 |
"""Assert that the specified outcomes appear with the respective |
| 49 |
numbers (0 means it didn't occur) in the text output from a test run.""" |
| 50 |
__tracebackhide__ = True |
| 51 |
|
| 52 |
obtained = { |
| 53 |
"passed": outcomes.get("passed", 0), |
| 54 |
"skipped": outcomes.get("skipped", 0), |
| 55 |
"failed": outcomes.get("failed", 0), |
| 56 |
"errors": outcomes.get("errors", 0), |
| 57 |
"xpassed": outcomes.get("xpassed", 0), |
| 58 |
"xfailed": outcomes.get("xfailed", 0), |
| 59 |
} |
| 60 |
expected = { |
| 61 |
"passed": passed, |
| 62 |
"skipped": skipped, |
| 63 |
"failed": failed, |
| 64 |
"errors": errors, |
| 65 |
"xpassed": xpassed, |
| 66 |
"xfailed": xfailed, |
| 67 |
} |
| 68 |
if warnings is not None: |
| 69 |
obtained["warnings"] = outcomes.get("warnings", 0) |
| 70 |
expected["warnings"] = warnings |
| 71 |
if deselected is not None: |
| 72 |
obtained["deselected"] = outcomes.get("deselected", 0) |
| 73 |
expected["deselected"] = deselected |
| 74 |
assert obtained == expected |