New issue 757: Heavily using decorators in the System under test suppresses exceptions https://bitbucket.org/pytest-dev/pytest/issue/757/heavily-using-decorators-in-the-system
Maxim Yaskevich: py.test version - ``platform win32 -- Python 2.7.9 -- py-1.4.27 -- pytest-2.7.1`` When a class I write my tests for heavily uses decorators, for instance for implementing a "builder" fluent method interface like below: ``` #!python from functools import wraps def fluent(method): @wraps(method) def inner(self, *args, **kwargs): try: method(self, *args, **kwargs) finally: return self return inner class Server(object): def __init__(self, host, port=9090): self.host = host self.port = port self.isrunning = False self.status = None self.response = None @fluent def start(self): self.isrunning = True print 'started' @fluent def request(self, url, context=None): assert self.isrunning print 'requesting', url, '...' self.status, self.response = 404, {'error': 'Page not found'} @fluent def await_response(self, status): print 'assert expected', status, 'got', self.status assert status == self.status # Generates AssertionError def test_simple(): Server('localhost', port=9000) \ .start() \ .request('/is_prime', {'number': 13}) \ .await_response(200) ``` the test passes. I think this is absolutely not fair and dangerous, as it can hide real problems from the people. The thing that surprised me even more is that ``nose`` didn't get to catch that error either. Am I missing something? Please run a test sample in the attachment, and feel free to ask for more details if needed. _______________________________________________ pytest-commit mailing list pytest-commit@python.org https://mail.python.org/mailman/listinfo/pytest-commit