Serhiy Storchaka <[email protected]> added the comment:
What to do with comprehensions and classes? Corresponding code objects are not
easily accessible and they do not have corresponding function. It would be
difficult to use the locals of the frame with comprehensions.
Maybe use per-module registries of qualnames?
class MyAssertions:
def assertComplexState(self, inputs):
self.assertEqual('42', inputs[0], 'the input %s is not the right
answer' % inputs)
__unittests = {'MyAssertions.assertComplexState'}
The frame is skipped if f_globals['__unittests'] contains co_qualname or any
parents of co_qualname.
We can even add a decorator:
def assertion(func):
mod = sys.modules[func.__module__]
mod.__dict__.setdefault('__unittests', set())
mod.__setdefault.add(func.__qualname__)
return func
----------
nosy: +serhiy.storchaka
versions: +Python 3.11 -Python 3.4
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue1705520>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com