Skip to content

pytest class with different parameters #9290

Answered by The-Compiler
SebastianZa asked this question in Q&A
Discussion options

You must be logged in to vote

The setup_class and teardown_class methods you describe are actually from pytest's support of unittest/nose, and not the "native" way of doing this with pytest.

A more pytest-like and powerful mechanism to achieve the same goal are pytest's fixtures - they'll take a bit of time to wrap your head around, but are totally worth it!

Your code could perhaps look like this (with a couple of assumption, your original code has various issues):

class Test_HW:

    @pytest.fixture(autouse=True)
    def interface(self):
        # before every test
        init_if(chosen_if)
        yield
        # after every test
        deinit_if(chosen_if)

    def test_nr1(self):
        # do anything

    def t…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SebastianZa
Comment options

Answer selected by SebastianZa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants