Comment #2 on issue 1208 by [email protected]: allow listeners to
receive suite, test case and keyword objects as arguments
http://code.google.com/p/robotframework/issues/detail?id=1208
After implementing this on my machine, I think we can do better. Instead of
passing in a suite, testcase, or keyword depending on the method, why not
have a single "test run" object that contains all of that information? For
example:
def start_keyword(self, testrun):
print " current suite:", testrun.suite
print " current test:", testrun.testcase
print "current keyword:", testrun.keyword
Of course, these values could be None depending on the context. For
example, testrun.testcase and testrun.keyword would be None when
start_suite and end_suite are called.
I like this better because it's easy to document (and thus easier to learn
and use), and because it's more extensible. We can evolve the Testrun class
over time to include other information that might be useful to the listener
interface (eg: namespace, current statistics, etc). This makes it really
easy to pass more information to the listener without having to add yet
another listener api.
Another advantage is that if the test runner ever changed to support
debugging features such as skipping or rerunning tests or keywords, etc,
that functionality can be implemented via this object without having to add
yet another listener interface. For example, maybe a listener could cause
the current suite to abort with "testrun.abort('killed by the listener')".
Obviously this means that the Testrun class is tightly coupled to the test
runner, but better than that trying to put that coupling deeper, at the
suite, test and keyword object layer.