0

I write testing code using flask_testing

following is my testing code

from app import create_app, db

class SampleTest(TestCase):
    def create_app(self):
        self.db_fd, self.db_path = tempflie.mkstemp()
        return create_app({'DATABASE': self.db_path})

    def setUp(self):
        db.create_all()

    def tearDown(self):
        db.session.remove()
        db.drop_all()
        os.close(self.db_fd)
        os.unlink(self.db_path)

    def test1(self):
        response = self.get('/test1/')

    def test2(self):
        response = self.get('/test2/')

when I debug the test code, I found that create_app is called in all test functions, including test1, test.

how can i call create_app function only once?

fuzes
  • 1,777
  • 4
  • 20
  • 40

1 Answers1

0
def create_app(self):
    self.db_fd, self.db_path = tempflie.mkstemp()
    return create_app({'DATABASE': self.db_path})

This is confusing and I suspect not intended you import create_app and have a method called create_app.

Also do you have a @pytest.fixture on your imported create_app?

Georges Lorré
  • 443
  • 3
  • 11