Pytest AttributeError: 'TestMyTest' object has no attribute

Question:

I have multiple tests written in the following format. When the test is run, why do some tests fail with exception AttributeError: 'TestMyTest' object has no attribute 'var1'?

var1 is defined as class variable in test_init(). Still the exception is thrown in test_1().

@pytest.fixture(scope="module")
def do_setup(run_apps):
    """
    Do setup
    """
    # Do something
    yield some_data


class TestMyTest(BaseTestClass):
    ids = dict()
    task_id = list()
    output_json = None

    def test_init(self, do_setup):
        TestMyTest.var1 = Feature1()

    def test_1(self):
        self._logger.info("self.var1: {}".format(self.var1))
Asked By: user2622678

||

Answers:

var1 was not defined as test_init() failed.

Answered By: user2622678
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.