Just from my experience testing more complex apps which have some
framework enhancements.
Don't overdo the mocking, it's far to easy to have tests which work fine
with mocks, but the regular code with real objects fails. I tend to use
mocking for edge cases only, where I want to test exception handling and
the like.
With pytest it's fairly easy to parametrize a fixture and provide a db
connection with both in memory sqlite and something like postgres. For
regular development you let the tests run quickly with in memory sqlite
and before merging or just from time to time or via a CI system you test
with the real db.
Try to write your stuff in a way that you don't rely too much on the db
side of models, then it's easier to replace them with mocks. I often use
wrapper classes which add more functionality instead of adding that
directly to the models. Composition instead of inheritance etc.
IMO pyramid and pyramid-sqlalchemy have good examples on how to do
testing with a framework. The latter has good support for savepoints, so
you don't have to setup your db content all the time, but can just
rollback after each test. AFAIK it support pytest fixtures, or at least
provides helpers which make it easy to write fixtures. I haven't used
pyramid-sqlalchemy myself yet, but in a project I'm involved in we use a
pretty similar way to do the same thing.
https://pyramid-sqlalchemy.readthedocs.org/en/latest/tests.html
I haven't switched any of my app test suites to pytest yet. One I got
working, but it's currently slower than zope.testrunner with layers, so
it's postponed. The new pyramid-sqlalchemy test helpers should make that
better though. I hope to be able to try again soon. I have converted
quite a few other python packages of mine to pytest though.
Regards,
Florian Schulze
On 7 May 2015, at 17:49, AryƩ H wrote:
Hi,
Our question is on the right approach to testing such a framework ?
1) start with low level unit tests and strive to mock out the DB
2) continue with higher level integration tests with a DB and data
fixtures
More specifically
(1) What is the best way to write unit tests that need model
definitions
(without database)
and (2) integration tests that need database access in a framework
that
relies on Pyramid+SQLA but doesn't have any models defined in the
code.
Thanks for the follow up!
Any advice would be greatly appreciated.
Message: 1
Date: Wed, 6 May 2015 11:38:34 +0000
From: holger krekel <[email protected]>
To: Brianna Laugher <[email protected]>
Cc: "[email protected]" <[email protected]>, Chris Hart
<[email protected]>
Subject: Re: [pytest-dev] adopt pytest month is over!
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Hi Brianna!
thanks for this great initiative! I am also looking forward to the
survey.
Note sure i can help myself but are there some notes/summary of what
is
the problem with Nefertari currently?
best,
holger
_______________________________________________
pytest-dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-dev
_______________________________________________
pytest-dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-dev