On 8 Apr 2014, at 15:19, Alexey Kuchm wrote:
I've lost my working day trying to setup basic thing:
*Database for unit testing*
What I need:
1) Functional tests, based on TestApp, full web-stack.
This works OK.
Due to *pyramid_tm*, transacion is either committed or rolled back
2) Unit/integration/whatever tests, w/o web-stack
- every test may create objects before calling methods
- methods being tested create objects
- after each test, objects are removed from DB
No success.
*All the tests are run inside ONE BIG transaction which is rolled back
after ALL tests are done. *
Pyramid project initializes DB as follows (standard way):
DBSession =
scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
ModelBase = declarative_base()
All methods being tested work with database through this DBSession.
Typical test:
def test_get(self):
mgr = EndpointManager()
r = mgr.create('endpoint3', 'xxx')
created = mgr.get(r)
self.assertIsNotNone(created)
The object 'endpoint3' will be present in DB during execution of other
tests. And it disappears as soon as all test are done. I think it is
totally wrong to run all tests in ONE trans. Instead, every test must
run
inside individual trans.
There is some hint but it does not work:
http://sontek.net/blog/detail/writing-tests-for-pyramid-and-sqlalchemy
Nothing is rolled back and warning is printed:
SAWarning: At least one scoped session is already present.
configure() can
not affect sessions that have already been created
Please, give me hint/idea how to setup 'transaction per test'.
The Kotti project does this with pytest fixtures. Looking at
https://github.com/Kotti/Kotti/blob/master/kotti/tests/__init__.py (esp.
db_session and connection) should get you started.
HTH,
Andreas
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.