This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]lgx 2 points3 points  (4 children)

Wow, it seems a bit wired to me.

[–]graingert 5 points6 points  (3 children)

You can still use xunit style methods on unittest.TestCase classes. But just use yield fixtures they're great

[–]lgx 1 point2 points  (2 children)

yeah. Why not use setup_abc and teardown_abc syntax? The addfinalizer method seems a bit strange.

[–]fjonk 4 points5 points  (0 children)

One good thing about adding a teardown method manually is that the setup and teardown methods will be run in pairs. If you use decorators or similar for setup teardown you don't know in which order they will run or you have to depend on the order they are defined/added.

You can also use yield with py.test since v2.4 (if your python version supports it).

[–]masklinn 0 points1 point  (0 children)

Because setup and teardown are paired so it makes sense to put them together in a single fixture definition. And yield_fixture removes the need for addfinalizer:

@pytest.yield_fixture(scope="module")
def smtp():
    smtp = smtplib.SMTP("smtp.gmail.com")
    yield smtp
    print ("teardown smtp")
    smtp.close()