-
-
Save einSelbst/6dd2d17e670f416271c45c4f27610e6f to your computer and use it in GitHub Desktop.
Revisions
-
kissgyorgy renamed this gist
May 25, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,14 +21,14 @@ def dbsession(engine, tables): """Returns an sqlalchemy session, and after the test tears down everything properly.""" connection = engine.connect() # begin the nested transaction transaction = connection.begin() # use the connection with the already started transaction session = Session(bind=connection) yield session session.close() # roll back the broader transaction transaction.rollback() # put back the connection to the connection pool connection.close() -
kissgyorgy revised this gist
May 24, 2015 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,16 +3,19 @@ from myapp.models import BaseModel import pytest @pytest.fixture(scope='session') def engine(): return create_engine('postgresql://localhost/test_database) @pytest.yield_fixture(scope='session') def tables(engine): BaseModel.metadata.create_all(engine) yield BaseModel.metadata.drop_all(engine) @pytest.yield_fixture def dbsession(engine, tables): """Returns an sqlalchemy session, and after the test tears down everything properly.""" -
kissgyorgy revised this gist
May 24, 2015 . 1 changed file with 10 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,13 +3,19 @@ from myapp.models import BaseModel import pytest @pytest.fixture(scope='session') def engine(): return create_engine('postgresql://localhost/test_database) @pytest.yield_fixture(scope='session') def tables(engine): BaseModel.metadata.create_all(engine) yield BaseModel.metadata.drop_all(engine) @pytest.yield_fixture def dbsession(engine, tables): """Returns an sqlalchemy session, and after the test tears down everything properly.""" connection = engine.connect() # begin the nested transaction transacton = connection.begin() @@ -21,7 +27,5 @@ def dbsession(): session.close() # roll back the broader transaction transacton.rollback() # put back the connection to the connection pool connection.close() -
kissgyorgy created this gist
May 24, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ from sqlalchemy import create_engine from sqlalchemy.orm import Session from myapp.models import BaseModel import pytest @pytest.yield_fixture def dbsession(): """Returns an sqlalchemy session, and after the test tears down everything properly.""" engine = create_engine('postgresql://localhost/test_database') # create the tables before we start the transaction BaseModel.metadata.create_all(engine) connection = engine.connect() # begin the nested transaction transacton = connection.begin() # use the connection with the already started transaction session = Session(bind=connection) yield session session.close() # roll back the broader transaction transacton.rollback() # now we can delete the tables and wont hang BaseModel.metadata.drop_all(engine) # put back the connection to the connection pool connection.close()