0
class TestUM(unittest.TestCase):
    def test_Dynasty_init(self):
        try:
            self.p = ModelInterface(r"E:\HIL\07_Tests\AT_Dynasty_models\AT745\RTM_AT_745.dml") #any dml file should do here
        except Exception:
            self.fail("Dynasty initialization raised ExceptionType unexpectedly!")

    def test_Dynasty_check(self):
        self.p.check()

At line 9 I am getting the following error:

"AttributeError: 'TestUM' object has no attribute 'p'"

I don't understand. self.p is not getting recognized in the test_Dynasty_check function.

2
  • Those are two separate test cases. Commented Jul 28, 2017 at 20:44
  • 2
    Each test method is called on a separate instance of TestUM. Either rename test_Dynasty_init to setUp, or combine the two into a single method. Commented Jul 28, 2017 at 20:44

2 Answers 2

3

You should use setUp() and tearDown() for initialization/destruction code.

If I remember correctly, the unittest library runs all functions starting with test in alphabetical order. Meaning that test_Dynasty_check is running before test_Dynasty_init. EDIT: The order doesn't matter, since each test will be run from a new instance of the TestCase class.

Sign up to request clarification or add additional context in comments.

1 Comment

I wouldn't even count on the test methods being executed in any particular order. Individual tests should be independent of each other.
0

That probably depends on whether test_Dynasty_init() is actually called before test_Dynasty_check() for your class instance.

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.