Yelp / Testify

A more pythonic testing framework.
Other
308 stars 67 forks source link

improve use of TestResult for EVENT_ON_COMPLETE_TEST_CASE #121

Closed mrtyler closed 8 years ago

mrtyler commented 11 years ago

As addressed in issue #116, we needed a way for clients to communicate to the server when they had completed running a test case and its fixtures. We did this by making a test result with test_method_name run.

This solution makes the code unclear. It forces us to hardcode the string run in a number of places when checking whether a test result is one of these special results signaling that a test case is complete.

The TestResult constructor wants an actual method, which it inspects to determine the method name (and class name, so it must be a method and not a function!). We use TestCase.run for this since it is the method that creates the test result. I tried using a dedicated method with a more descriptive name (test_case_complete) but it didn't work. I gave up because I'm pretty sure @EvanKrall and I went down that road when we started working on this problem.

An improvement would be to add a flag to TestResult to represent this situation. That would be clearer than checking for a specific test_method_name.

A further, more complicated improvement would be to use some other mechanism for communication of doneness between client and server. Using a TestResult forces consumers to check their test results and make sure they are really reporting the results of a test, and not just communicating some internal state.

EvanKrall commented 11 years ago

A suggestion: maybe just make an inheritance tree:

and override to_dict on each class to add a type attribute.

asottile commented 8 years ago

Obsolete via #317