[apparmor] [patch] simplify setup_all_tests() call in utils test

Christian Boltz apparmor at cboltz.de
Thu Mar 5 17:59:26 UTC 2015


Hello,

Am Mittwoch, 4. März 2015 schrieb Seth Arnold:
> On Thu, Mar 05, 2015 at 01:22:47AM +0100, Christian Boltz wrote:
> > BTW: If I had noticed earlier that __name__ is always '__main__',
> > I'd have implemented the simplified way from the beginning.
> 
> But is it always __main__? The whole point of the guard is that the
> files may be called in multiple ways and with different tools,
> perhaps including test runners that do different things...

Well, if __name__ is not '__main__' for some reason [1], the if 
condition won't match and the function won't be called. (In this case, 
unittest.main() also won't be called.)

So _if_ the function is called, it _is_ always '__main__' ;-)


Regards,

Christian Boltz

[1] the only possible reason I can imagine is that something else 
    has a "import test-foo" or "from test-foo import bar" - and in those 
    cases setup_all_tests and unittest.main() of the imported module
    won't run
-- 
Superior to what?  Yes, HTML is superior at transporting viruses and 
malware onto your computer or causing other inappropriate actions to 
occur. [Tom Taylor in opensuse-factory about HTML mails]




More information about the AppArmor mailing list