1

In the following code

class TestSomething(unittest.TestCase):
    def setUp(self):
        print("setting up")

    @unittest.skip("skip reason")
    def test_1(self):
        print("in test 1")

    def test_2(self):
        print("in test 2")

I expect only test_2 to run. But both the tests are running. I suspect that this is due to the setUp function, because if I remove it then only test_2 runs, as expected.

Is there a fix for this?

1 Answer 1

1

@unittest.skip(reason) works fine with setUp method, can't reproduce it.

E.g. test_something.py:

import unittest


class TestSomething(unittest.TestCase):
    def setUp(self):
        print("setting up")

    @unittest.skip("skip reason")
    def test_1(self):
        print("in test 1")

    def test_2(self):
        print("in test 2")


if __name__ == '__main__':
    unittest.main()

unit test results:

ssetting up
in test 2
.
----------------------------------------------------------------------
Ran 2 tests in 0.000s

OK (skipped=1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.