[py-dev] KeyboardInterrupt during setup() and teardown()

Ronny Pfannschmidt Ronny.Pfannschmidt at gmx.de
Thu Jul 12 23:23:32 CEST 2012


Hi all,

my bad, that start call should have been named ensure_started

On 07/12/2012 10:30 PM, holger krekel wrote:
> Hi Pärham, Ronny,
>
> On Thu, Jul 12, 2012 at 15:26 +0200, Ronny Pfannschmidt wrote:
>> Hi Pärham,
>>
>> as i already explained in irc before,
>> a cached setup only calls tear-down if it was successful,
>>
>> and if you want it to work property, you should split it up
>>
>> an example of doing that would be something like
>>
>> def pytest_funcarg__app(request):
>>    def setup()
>>       return create_app()  # FAST
>>    def teardown(app):
>>       app.stop()
>>    app = request.cached_setup(setup, teardown, scope='session')
>>    app.start() #can wait
>>    return app
>
> I don't think this is correct as it would start() the app
> in each test function that uses the "app" funcarg.
>
> It's indeed unusual that despite a failing setup you
> want to do some teardown.  Maybe in this case controling
> it yourself is the best:
>
>      def setup():
>          try:
>              app.start()
>          except Exception: # or KeyboardInterrupt etc.
>              app.stop()
>              raise
>
> hth,
> holger
>
> http://codespeak.net/mailman/listinfo/py-dev




More information about the Pytest-dev mailing list