08-errors.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from pathlib import Path
  2. from proxytester.main import BaseProxyTest, ProxyConfig
  3. class ErroredTest(BaseProxyTest):
  4. """A test that raise an exception to demonstrate the difference
  5. between failed test and errored test
  6. """
  7. def __init__(self):
  8. super().__init__()
  9. self.description = "A test that produces an error (Error)"
  10. self.proxy_config = ProxyConfig(
  11. binary_path=Path.home() / "bin/haproxy"
  12. )
  13. async def run_test(self):
  14. await self.make_request()
  15. # This will fail with the standard error message
  16. return False
  17. class ErroredExceptionTest(BaseProxyTest):
  18. """Also raising an exception in run_test() produces an errored
  19. test
  20. """
  21. def __init__(self):
  22. super().__init__()
  23. self.description = "A test that produces an exception (Error)"
  24. self.proxy_config = ProxyConfig(
  25. binary_path=Path.home() / "bin/haproxy"
  26. )
  27. async def run_test(self):
  28. await self.make_request()
  29. # There's no need of returning bool here
  30. raise RuntimeError("This must fail with custom message")