1

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))
vvvvv
  • 25,404
  • 19
  • 49
  • 81
user2622678
  • 393
  • 1
  • 7
  • 17
  • 4
    Apparently `test_init()` was not called. Why do you think it should have been called before `test_1()`? – mkrieger1 Apr 04 '23 at 15:10

1 Answers1

0

var1 was not defined as test_init() failed.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
user2622678
  • 393
  • 1
  • 7
  • 17