distreporter.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # -*- test-case-name: twisted.trial._dist.test.test_distreporter -*-
  2. #
  3. # Copyright (c) Twisted Matrix Laboratories.
  4. # See LICENSE for details.
  5. """
  6. The reporter is not made to support concurrent test running, so we will
  7. hold test results in here and only send them to the reporter once the
  8. test is over.
  9. @since: 12.3
  10. """
  11. from zope.interface import implementer
  12. from twisted.trial.itrial import IReporter
  13. from twisted.python.components import proxyForInterface
  14. @implementer(IReporter)
  15. class DistReporter(proxyForInterface(IReporter)):
  16. """
  17. See module docstring.
  18. """
  19. def __init__(self, original):
  20. super(DistReporter, self).__init__(original)
  21. self.running = {}
  22. def startTest(self, test):
  23. """
  24. Queue test starting.
  25. """
  26. self.running[test.id()] = []
  27. self.running[test.id()].append((self.original.startTest, test))
  28. def addFailure(self, test, fail):
  29. """
  30. Queue adding a failure.
  31. """
  32. self.running[test.id()].append((self.original.addFailure,
  33. test, fail))
  34. def addError(self, test, error):
  35. """
  36. Queue error adding.
  37. """
  38. self.running[test.id()].append((self.original.addError,
  39. test, error))
  40. def addSkip(self, test, reason):
  41. """
  42. Queue adding a skip.
  43. """
  44. self.running[test.id()].append((self.original.addSkip,
  45. test, reason))
  46. def addUnexpectedSuccess(self, test, todo=None):
  47. """
  48. Queue adding an unexpected success.
  49. """
  50. self.running[test.id()].append((self.original.addUnexpectedSuccess,
  51. test, todo))
  52. def addExpectedFailure(self, test, error, todo=None):
  53. """
  54. Queue adding an unexpected failure.
  55. """
  56. self.running[test.id()].append((self.original.addExpectedFailure,
  57. test, error, todo))
  58. def addSuccess(self, test):
  59. """
  60. Queue adding a success.
  61. """
  62. self.running[test.id()].append((self.original.addSuccess, test))
  63. def stopTest(self, test):
  64. """
  65. Queue stopping the test, then unroll the queue.
  66. """
  67. self.running[test.id()].append((self.original.stopTest, test))
  68. for step in self.running[test.id()]:
  69. step[0](*step[1:])
  70. del self.running[test.id()]