Pytest unittest-style setup: module setup

Question:

Pytest documentation describes four ways to setup/teardown things:

  • module level setup/teardown
  • class level setup/teardown
  • method level setup/teardown
  • function level setup/teardown

But in one project it was implemented like this:

class TestClass:
    def setup(self):
        ...
    def test_1(self):
        ...
    ...

This setup method is called around each method invocation, just like setup_method from documentation (except that it doesn’t take method as an argument). But I haven’t seen it in the documentation or anywhere else. Why does it work?

Asked By: Mikhail Mishin

||

Answers:

Check this code
https://pytest.org/latest/_modules/_pytest/python.html

I would guess it’s inheriting and using

def setup(self):
Answered By: mar

It’s part of nose testing framework which is integrated in pytest. More information you can find here

Answered By: kosciej16
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.