Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
unit tests failing because app.close calls sys.exit #313
I just upgraded from 2.4 -> 2.6 and my unit tests started failing because I'm calling CementApp.close() (as is done in the example at http://builtoncement.com/2.6/dev/testing.html), and that in turn appears to be calling sys.exit(). The tests don't fail when using 2.4.
I can't find any mention of this change of behaviour in the documentation, and I can't see a warning in the change log (sorry if I'm just being blind). Was it an intentional change? Personally I don't think it's a good idea for a framework to call sys.exit() unless explicitly told to do so, because the bootstrap code might want to do other stuff after the application is closed (in this case, it wants to continue running tests). Is there a way to prevent it, or to achieve the same effect as close() without the sys.exit()? If so, perhaps a description of how to do this could be added to the documentation?
Traceback (most recent call last):
I just ran into this issue myself after upgrading another app to Cement 2.6, and my immediately thought was "Eww.... yeah, probably should't have implemented sys.exit()". I think this change will be reverted and be more explicit, perhaps like needing to call 'app.exit()'.
I worked around this by sub-classing my app and creating a separate app for testing that catches
class MyTestApp(MyApp): def close(self, *args, **kw): try: super(MyTestApp, self).close(*args, **kw) except SystemExit as e: # ignore SystemExit from app.close() for tests pass
In my tests I do something like:
def test_myapp(self): app = MyTestApp(argv=['some-command', '--foo=bar']) with app: app.run()
Will keep this issue and slate it for Cement 2.8 to remove the implicit call to
Sorry, I just looked at the code for
So, you could disable this feature by:
class MyApp(CementApp): class Meta: exit_on_close = False
Alternatively, if you want to keep it but just disable it for testing you could follow the above example of sub-classing to a test app and just overriding the
Hope that helps!