You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.9KB

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