Decorator works for Function but not Class


Need a bit of help correcting a decorator for unittest. I'm not sure how to meet the requirements of unit test. The idea of this decorator is to mark the test as an expectedFailure IF True is passed in. Otherwise allow the test to simply run. This decorator works for test functions but doesn't work for class definitions



The error that I'm getting is test_sometest() takes exactly 1 argument. Removing the decorator allows the test to run. Moving the decorator to top of function allows the test to run.



History... One of my platforms works fine and the other platform does not. I want to allow one platform to run all the tests while the other platform will be marked as expected failures. Of course I do not want to use skip or skip if. Since that won't allow the valid platform to run. Marking them as expected failure will also not work since one platform will return unexpected success. With the expectedFailureIf() in place each platform will correctly report and once things are fixed these tests will report as unexpected success. Which will notify ME when things are fixed. For me... this seems a better outcome.



On Python 3 your code is working fine. The implementation of unittest.expectedFailure is better there, and it works correctly when decorating on either classes or functions.



On Python 2, the unittest.expectedFailure is only designed to work on functions.



Here's a replacement which works on Python 2.



Result:



The fact that an unexpected success doesn't fail the test run is a bug in Python! It was addressed back in Jan 2014 (Python 3.4), but this bugfix was not merged into 2.7's branch due to backwards compatibility concerns (see the comments on issue20165). So, that's now a Python 2 "feature", unfortunately.



If this is a deal-breaker to you, consider upgrading to a more recent Python version and/or using a better test runner.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

佛陀 (漫畫)

Đế Bá

文学批评