Skip to content

Cannot run tests with testing.postgresql - application is not being found and failes to shutdown the server automatically #42

@krzysztofcyran93

Description

@krzysztofcyran93

Hello, the below appears when following the guide:

ERROR: tearDownModule (__main__)
----------------------------------------------------------------------
TypeError: tearDownModule() missing 1 required positional argument: 'self'

I'm not quite sure how is this supposed to work, since the mehod is outside of the TestCase class

import unittest
import testing.postgresql

def tearDownModule(self):
    Postgresql.clear_cache()

class Base(unittest.TestCase):

    def setUp(self) -> None:
        self.postgresql = Postgresql()
        print(self.postgresql.url())

    def tearDown(self) -> None:
        self.postgresql.stop()

class TestInitial(Base):
    def some_test_suite(self):
        print('Test this works')

def some_test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestInitial))
    return suite

if __name__ == '__main__':
    with testing.postgresql.Postgresql() as postgresql:
        engine = create_engine(postgresql.url())
        db = psycopg2.connect(**postgresql.dsn())
        runner = unittest.TextTestRunner()
        runner.run(some_test_suite())

Next what happens is two things:

No application found. Either work inside a view function or push an application context. See http://flask-sqlalchemy.pocoo.org/contexts/.

and

ERROR: testing.common.database: failed to shutdown the server automatically. Any server processes and files might have been leaked. Please remove them and call the stop() certainly

Full log:

postgresql://postgres@127.0.0.1:47359/test
No application found. Either work inside a view function or push an application context. See http://flask-sqlalchemy.pocoo.org/contexts/.
.
----------------------------------------------------------------------
Ran 1 test in 0.807s

OK
ERROR: testing.common.database: failed to shutdown the server automatically.
Any server processes and files might have been leaked. Please remove them and call the stop() certainly
ERROR: testing.common.database: failed to shutdown the server automatically.
Any server processes and files might have been leaked. Please remove them and call the stop() certainly

I've been struggling with this for quite a while and I will appreciate any feedback. Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions