import unittest
import os

os.environ['OGN_CONFIG_MODULE'] = 'config/test.py'

from ogn_python import db   # noqa: E402


class TestBaseDB(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        db.session.execute('CREATE EXTENSION IF NOT EXISTS postgis;')
        db.session.commit()
        db.create_all()

    def setUp(self):
        pass

    def tearDown(self):
        db.session.execute("""
            DELETE FROM aircraft_beacons;
            DELETE FROM receiver_beacons;
            DELETE FROM takeoff_landings;
            DELETE FROM logbook;
            DELETE FROM receiver_coverages;
            DELETE FROM device_stats;
            DELETE FROM receiver_stats;
            DELETE FROM receivers;
            DELETE FROM devices;
        """)


if __name__ == '__main__':
    unittest.main()

import unittest
import os

os.environ['OGN_CONFIG_MODULE'] = 'config/test.py'

from ogn_python import db   # noqa: E402


class TestBaseDB(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        db.drop_all()
        db.session.execute('CREATE EXTENSION IF NOT EXISTS postgis;')
        db.session.commit()
        db.create_all()

    def setUp(self):
        pass

    def tearDown(self):
        db.session.execute("""
            DELETE FROM aircraft_beacons;
            DELETE FROM receiver_beacons;
            DELETE FROM takeoff_landings;
            DELETE FROM logbook;
            DELETE FROM receiver_coverages;
            DELETE FROM device_stats;
            DELETE FROM receiver_stats;
            DELETE FROM receivers;
            DELETE FROM devices;
        """)


if __name__ == '__main__':
    unittest.main()

Drop db before each test
Drop db before each test

  import unittest
  import os
  
  os.environ['OGN_CONFIG_MODULE'] = 'config/test.py'
  
  from ogn_python import db   # noqa: E402
  
  
  class TestBaseDB(unittest.TestCase):
      @classmethod
      def setUpClass(cls):
+         db.drop_all()
          db.session.execute('CREATE EXTENSION IF NOT EXISTS postgis;')
          db.session.commit()
          db.create_all()
  
      def setUp(self):
          pass
  
      def tearDown(self):
          db.session.execute("""
              DELETE FROM aircraft_beacons;
              DELETE FROM receiver_beacons;
              DELETE FROM takeoff_landings;
              DELETE FROM logbook;
              DELETE FROM receiver_coverages;
              DELETE FROM device_stats;
              DELETE FROM receiver_stats;
              DELETE FROM receivers;
              DELETE FROM devices;
          """)
  
  
  if __name__ == '__main__':
      unittest.main()
  
Drop db before each test
## Code Before:
import unittest
import os

os.environ['OGN_CONFIG_MODULE'] = 'config/test.py'

from ogn_python import db   # noqa: E402


class TestBaseDB(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        db.session.execute('CREATE EXTENSION IF NOT EXISTS postgis;')
        db.session.commit()
        db.create_all()

    def setUp(self):
        pass

    def tearDown(self):
        db.session.execute("""
            DELETE FROM aircraft_beacons;
            DELETE FROM receiver_beacons;
            DELETE FROM takeoff_landings;
            DELETE FROM logbook;
            DELETE FROM receiver_coverages;
            DELETE FROM device_stats;
            DELETE FROM receiver_stats;
            DELETE FROM receivers;
            DELETE FROM devices;
        """)


if __name__ == '__main__':
    unittest.main()

## Instruction:
Drop db before each test
## Code After:
import unittest
import os

os.environ['OGN_CONFIG_MODULE'] = 'config/test.py'

from ogn_python import db   # noqa: E402


class TestBaseDB(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        db.drop_all()
        db.session.execute('CREATE EXTENSION IF NOT EXISTS postgis;')
        db.session.commit()
        db.create_all()

    def setUp(self):
        pass

    def tearDown(self):
        db.session.execute("""
            DELETE FROM aircraft_beacons;
            DELETE FROM receiver_beacons;
            DELETE FROM takeoff_landings;
            DELETE FROM logbook;
            DELETE FROM receiver_coverages;
            DELETE FROM device_stats;
            DELETE FROM receiver_stats;
            DELETE FROM receivers;
            DELETE FROM devices;
        """)


if __name__ == '__main__':
    unittest.main()
