Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to do when a py.test hangs silently?

While using py.test, I have some tests that run fine with SQLite but hang silently when I switch to Postgresql. How would I go about debugging something like that? Is there a "verbose" mode I can run my tests in, or set a breakpoint ? More generally, what is the standard plan of attack when pytest stalls silently? I've tried using the pytest-timeout, and ran the test with $ py.test --timeout=300, but the tests still hang with no activity on the screen whatsoever

like image 693
Hexatonic Avatar asked Oct 14 '14 00:10

Hexatonic


1 Answers

I ran into the same SQLite/Postgres problem with Flask and SQLAlchemy, similar to Gordon Fierce. However, my solution was different. Postgres is strict about table locks and connections, so explicitly closing the session connection on teardown solved the problem for me.

My working code:

@pytest.yield_fixture(scope='function') def db(app):     # app is an instance of a flask app, _db a SQLAlchemy DB     _db.app = app     with app.app_context():         _db.create_all()      yield _db      # Explicitly close DB connection     _db.session.close()      _db.drop_all() 

Reference: SQLAlchemy

like image 163
kelaraj Avatar answered Oct 05 '22 16:10

kelaraj