This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients Julian, amaury.forgeotdarc, dmalcolm, michael.foord, purcell, rbcollins, rhettinger, serhiy.storchaka
Date 2021-09-05.17:45:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1630863939.88.0.0799780595915.issue1705520@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2021-09-05 17:45:39serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, purcell, amaury.forgeotdarc, rbcollins, michael.foord, dmalcolm, Julian
2021-09-05 17:45:39serhiy.storchakasetmessageid: <1630863939.88.0.0799780595915.issue1705520@roundup.psfhosted.org>
2021-09-05 17:45:39serhiy.storchakalinkissue1705520 messages
2021-09-05 17:45:39serhiy.storchakacreate