Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
krzysztofcyran93 opened this issue Jul 16, 2022 · 0 comments

Comments

@krzysztofcyran93
Copy link

krzysztofcyran93 commented Jul 16, 2022

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://[email protected]: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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant