1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
7 Maintainer: Jonathan Lange
10 import zope.interface as zi
11 from zope.interface import Attribute
14 class ITestCase(zi.Interface):
16 The interface that a test case must implement in order to be used in Trial.
19 failureException = zi.Attribute(
20 "The exception class that is raised by failed assertions")
25 Run the test. Should always do exactly the same thing as run().
31 Return the number of tests in this test case. Usually 1.
37 Return a unique identifier for the test, usually the fully-qualified
44 Run the test, storing the results in C{result}.
46 @param result: A L{TestResult}.
50 def shortDescription():
52 Return a short description of the test.
57 class IReporter(zi.Interface):
59 I report results from a run of a test suite.
62 stream = zi.Attribute(
63 "Deprecated in Twisted 8.0. "
64 "The io-stream that this reporter will write to")
65 tbformat = zi.Attribute("Either 'default', 'brief', or 'verbose'")
67 "Additional string argument passed from the command line")
68 shouldStop = zi.Attribute(
70 A boolean indicating that this reporter would like the test run to stop.
72 separator = Attribute(
73 "Deprecated in Twisted 8.0. "
74 "A value which will occasionally be passed to the L{write} method.")
77 The number of tests that seem to have been run according to this
82 def startTest(method):
84 Report the beginning of a run of a single test method.
86 @param method: an object that is adaptable to ITestMethod
92 Report the status of a single test method
94 @param method: an object that is adaptable to ITestMethod
100 Deprecated in Twisted 8.0.
102 Suites which wish to appear in reporter output should call this
103 before running their tests.
109 Deprecated in Twisted 8.0.
111 Called at the end of a suite, if and only if that suite has called
116 def cleanupErrors(errs):
118 Deprecated in Twisted 8.0.
120 Called when the reactor has been left in a 'dirty' state
122 @param errs: a list of L{twisted.python.failure.Failure}s
126 def upDownError(userMeth, warn=True, printStatus=True):
128 Deprecated in Twisted 8.0.
130 Called when an error occurs in a setUp* or tearDown* method
132 @param warn: indicates whether or not the reporter should emit a
133 warning about the error
135 @param printStatus: indicates whether or not the reporter should
136 print the name of the method and the status
137 message appropriate for the type of error
138 @type printStatus: Boolean
142 def addSuccess(test):
144 Record that test passed.
148 def addError(test, error):
150 Record that a test has raised an unexpected exception.
152 @param test: The test that has raised an error.
153 @param error: The error that the test raised. It will either be a
154 three-tuple in the style of C{sys.exc_info()} or a
155 L{Failure<twisted.python.failure.Failure>} object.
159 def addFailure(test, failure):
161 Record that a test has failed with the given failure.
163 @param test: The test that has failed.
164 @param failure: The failure that the test failed with. It will
165 either be a three-tuple in the style of C{sys.exc_info()}
166 or a L{Failure<twisted.python.failure.Failure>} object.
170 def addExpectedFailure(test, failure, todo):
172 Record that the given test failed, and was expected to do so.
174 @type test: L{pyunit.TestCase}
175 @param test: The test which this is about.
176 @type error: L{failure.Failure}
177 @param error: The error which this test failed with.
178 @type todo: L{unittest.Todo}
179 @param todo: The reason for the test's TODO status.
183 def addUnexpectedSuccess(test, todo):
185 Record that the given test failed, and was expected to do so.
187 @type test: L{pyunit.TestCase}
188 @param test: The test which this is about.
189 @type todo: L{unittest.Todo}
190 @param todo: The reason for the test's TODO status.
194 def addSkip(test, reason):
196 Record that a test has been skipped for the given reason.
198 @param test: The test that has been skipped.
199 @param reason: An object that the test case has specified as the reason
200 for skipping the test.
206 Deprecated in Twisted 8.0, use L{done} instead.
208 Present a summary of the test results.
214 Deprecated in Twisted 8.0, use L{done} instead.
216 Present the errors that have occured during the test run. This method
217 will be called after all tests have been run.
223 Deprecated in Twisted 8.0, use L{done} instead.
225 Display a string to the user, without appending a new line.
231 Deprecated in Twisted 8.0, use L{done} instead.
233 Display a string to the user, appending a new line.
238 Return a boolean indicating whether all test results that were reported
239 to this reporter were successful or not.
245 Called when the test run is complete.
247 This gives the result object an opportunity to display a summary of
248 information to the user. Once you have called C{done} on an
249 L{IReporter} object, you should assume that the L{IReporter} object is