Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8118237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:25:09+00:00 2026-06-06T04:25:09+00:00

I am using py.test to write some tests and in my tests I utilize

  • 0

I am using py.test to write some tests and in my tests I utilize funcargs. These funcargs have their own setups and teardowns defined in the conftest.py like this:

conftest.py:

def pytest_funcarg__resource_name(request):
  def setup():
    # do setup
  def teardown():
    # do teardown

My problem is when someone uses CTRL+C to stop the test executions it leaves everything un-teardowned.
I know there is a hook pytest_keyboard_interrupt but I dont know what to do from there.

Sorry for the noobish question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:25:10+00:00Added an answer on June 6, 2026 at 4:25 am

    You don’t provide a full example so maybe i am missing something. But here is an example of how it can work, using the request.cached_setup() helper:

    def pytest_funcarg__res(request):
        def setup():
            print "res-setup"
        def teardown(val):
            print "res-teardown"
        return request.cached_setup(setup, teardown)
    
    def test_hello(res):
        raise KeyboardInterrupt()
    

    If you run this with “py.test” you get:

    ============================= test session starts ==============================
    platform linux2 -- Python 2.7.3 -- pytest-2.2.5.dev4
    plugins: xdist, bugzilla, pep8, cache
    collected 1 items
    
    tmp/test_keyboardinterrupt.py res-setup
    res-teardown
    
    
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! KeyboardInterrupt !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    /home/hpk/p/pytest/tmp/test_keyboardinterrupt.py:10: KeyboardInterrupt
    

    which shows that setup and teardown are called if a KeyboardInterrupt occurs during test execution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Test::Unit::TestCase to write some unit tests. Currently, I have a setup function
I'm using Google Test Framework to set some unit tests. I have got three
I am attempting to write some tests using webtest to test out my python
I'm attempting to write some unit tests using EasyMock and TestNG and have run
I'm writing some ruby (not Rails) and using test/unit with shoulda to write tests.
I'm trying to retrofit some tests using Test::More to legacy code and I've bumped
It has been decided to write some unit tests using moq etc..It's lots of
I want to write some unit tests for my COM object using googletest. Unfortunately
I've put up some tests using VisualStudio integrated test environment, they simultate what my
I am using Specflow (http://specflow.org/) to write some integration tests and I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.