[sqlalchemy] testing patterns with sqlalchemy 2.0

2022-08-31 Thread Chris Withers
Hi All, Are there any libraries (or anything in sqlalchemy itself!) that cover the pattern of running unit tests in against a database such that each test gets its own sterile environment in which to run? Postgres, if it helps. I've done some stuff with running in a subtransaction and rolling

[sqlalchemy] Testing and deprecation of nested transactions

2021-07-30 Thread Dejan Čabrilo
Hello everyone, I am working on a new project using SqlAlchemy Core 1.4 with Postgresql and wanted to implement the following pattern for my tests: - Before each test I would start a transaction (in a @pytest.fixture(autorun=True)) - Each test may create its own transactions - At the end of eac

Re: [sqlalchemy] Testing with a fake read replica

2020-03-11 Thread Mike Bayer
On Wed, Mar 11, 2020, at 2:17 PM, Colton Allen wrote: > Thank you. My use case didn't permit me to use your examples but, based on > your advice, I ended up using "after_flush_postexec" event. Any consequences > from doing this? Seems to work fine for now. this is just the test suite right? if

Re: [sqlalchemy] Testing with a fake read replica

2020-03-11 Thread Colton Allen
Thank you. My use case didn't permit me to use your examples but, based on your advice, I ended up using "after_flush_postexec" event. Any consequences from doing this? Seems to work fine for now. On Wednesday, March 11, 2020 at 12:34:12 PM UTC-5, Mike Bayer wrote: > > > > On Wed, Mar 11, 202

Re: [sqlalchemy] Testing with a fake read replica

2020-03-11 Thread Mike Bayer
On Wed, Mar 11, 2020, at 12:44 PM, Colton Allen wrote: > Hi, > > Before we talk about the read-replica, let's talk about the test suite as it > is. I have a sessionmaker in my test suite configured to use an external > transaction. Basically identical to this: > https://docs.sqlalchemy.org/en

[sqlalchemy] Testing with a fake read replica

2020-03-11 Thread Colton Allen
Hi, Before we talk about the read-replica, let's talk about the test suite as it is. I have a sessionmaker in my test suite configured to use an external transaction. Basically identical to this: https://docs.sqlalchemy.org/en/13/orm/session_transaction.html#joining-a-session-into-an-external

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-18 Thread Chris Withers
On 10/06/2019 15:40, Mike Bayer wrote: Okay, so sounds like in an ideal world, the framework should provide a way to sub out that transaction middleware when unit testing and then for functional testing, I just need to fall back to dropping everything in the db, or having a fresh db created fr

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-10 Thread Mike Bayer
On Mon, Jun 10, 2019, at 2:09 AM, Chris Withers wrote: > On 05/06/2019 20:47, Mike Bayer wrote: > > > > > >> The panacea I'm after is to be able to run the DDL in a transaction, run > >> each test in a subtransaction off that which is rolled back at the end > >> of each test, but also be able t

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-09 Thread Chris Withers
On 05/06/2019 20:47, Mike Bayer wrote: The panacea I'm after is to be able to run the DDL in a transaction, run each test in a subtransaction off that which is rolled back at the end of each test, but also be able to check that the code under test is doing session.commit() where it should. Whe

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-05 Thread Mike Bayer
On Wed, Jun 5, 2019, at 2:30 PM, Chris Withers wrote: > On 05/06/2019 17:15, Mike Bayer wrote: > > > >> How come close() doesn't rollback the SessionTransaction if it throws it > >> away? > > > > that's currently what .close() does, it discards the connection. this > > is safe because the conn

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-05 Thread Chris Withers
On 05/06/2019 17:15, Mike Bayer wrote: How come close() doesn't rollback the SessionTransaction if it throws it away? that's currently what .close() does, it discards the connection.   this is safe because the connection pool ensures transactions are rolled back.   This might have to change

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-05 Thread Mike Bayer
On Wed, Jun 5, 2019, at 11:47 AM, Chris Withers wrote: > On 05/06/2019 16:41, Mike Bayer wrote: > > > >> Which gives me: > >> > >> $ python sessions_are_weird.py > >> Traceback (most recent call last): > >> File "sessions_are_weird.py", line 40, in > >> assert session.query(Event).count() == 0

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-05 Thread Chris Withers
On 05/06/2019 16:41, Mike Bayer wrote: Which gives me: $ python sessions_are_weird.py Traceback (most recent call last):   File "sessions_are_weird.py", line 40, in     assert session.query(Event).count() == 0 AssertionError Whereas after the rollback, I'd expect that count to be zero... t

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-05 Thread Chris Withers
(sorry, meant to send this to the list) On 05/06/2019 15:52, Mike Bayer wrote: That session.close() appears to be the problem. It's a normal and required part of the code under test, but it throws away the SessionTransaction without rolling it back, so by the time the test does session.roll

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-05 Thread Mike Bayer
On Wed, Jun 5, 2019, at 3:50 AM, Chris Withers wrote: > On 04/06/2019 23:21, Mike Bayer wrote: > >> >> On Tue, Jun 4, 2019, at 4:33 PM, Chris Withers wrote: >>> >>> So, how do I roll back the further subtransaction created by the web >>> framework instantiating Session from a sessionmaker bou

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-05 Thread Mike Bayer
On Tue, Jun 4, 2019, at 6:31 PM, Chris Withers wrote: > On 04/06/2019 23:21, Mike Bayer wrote: > > > > > > I'm not following all your code but if there are two sessions in play > > I'd probably try to avoid that, there should be only one Session you > > care about. > > This comes back to so

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-05 Thread Chris Withers
On 04/06/2019 23:21, Mike Bayer wrote: On Tue, Jun 4, 2019, at 4:33 PM, Chris Withers wrote: So, how do I roll back the further subtransaction created by the web framework instantiating Session from a sessionmaker bound to the connection in which begin_nested() has been called, which under non

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-04 Thread Chris Withers
On 04/06/2019 23:21, Mike Bayer wrote: I'm not following all your code but if there are two sessions in play I'd probably try to avoid that, there should be only one Session you care about. This comes back to something I asked you about on Twitter a while ago: the code under test gets its

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-04 Thread Mike Bayer
On Tue, Jun 4, 2019, at 4:33 PM, Chris Withers wrote: > On 04/06/2019 14:49, Mike Bayer wrote: > > > > > > On Tue, Jun 4, 2019, at 2:15 AM, Chris Withers wrote: > >> Now, what I'm trying to test is that I haven't forgotten to include > >> the "with session.transaction". The problem is that, wi

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-04 Thread Chris Withers
On 04/06/2019 14:49, Mike Bayer wrote: On Tue, Jun 4, 2019, at 2:15 AM, Chris Withers wrote: Now, what I'm trying to test is that I haven't forgotten to include the "with session.transaction". The problem is that, without the transaction.rollback(), the test passes regardless of whether the

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-04 Thread Mike Bayer
On Tue, Jun 4, 2019, at 2:15 AM, Chris Withers wrote: > Hi All, > > I'm working with the pattern described at > https://docs.sqlalchemy.org/en/13/orm/session_transaction.html#joining-a-session-into-an-external-transaction-such-as-for-test-suites > along with pytest and FastAPI, an async web a

[sqlalchemy] testing that a session is committed correctly

2019-06-03 Thread Chris Withers
Hi All, I'm working with the pattern described at https://docs.sqlalchemy.org/en/13/orm/session_transaction.html#joining-a-session-into-an-external-transaction-such-as-for-test-suites along with pytest and FastAPI, an async web app framework with good support for running blocking code. So, I

Re: [sqlalchemy] testing/raising errors for queries that do not filter against themselves

2019-03-30 Thread Jonathan Vanasco
On Friday, March 29, 2019 at 7:35:02 PM UTC-4, Mike Bayer wrote: > > > I'm assuming you mean a double equals sign there. Yes. I am embarrassed > I think I was assuming that user would come back with a great success > story and this could be either on the wiki or maybe even an ext or a > fl

Re: [sqlalchemy] testing/raising errors for queries that do not filter against themselves

2019-03-29 Thread Mike Bayer
On Fri, Mar 29, 2019 at 4:39 PM Jonathan Vanasco wrote: > > I was going batty trying to figure out why a unit test kept passing, while > the functionality was clearly broken. > > I eventually realized the problem was a `filter` that didn't apply to the > actual query. > > The code was essentiall

[sqlalchemy] testing/raising errors for queries that do not filter against themselves

2019-03-29 Thread Jonathan Vanasco
I was going batty trying to figure out why a unit test kept passing, while the functionality was clearly broken. I eventually realized the problem was a `filter` that didn't apply to the actual query. The code was essentially this: result = s.query(Foo).filter(Bar.id = 1) but it was diffi

Re: [sqlalchemy] Testing against DB Connector IntegrityError?

2018-03-07 Thread KCY
Examining the stacktrace more closely revealed that I made the mistake of checking for the error on the add but left the context of that error check before committing. I actually did it the correct way in my all my other tests so I'm not sure why I made the mistake at the very end. My apologies

Re: [sqlalchemy] Testing against DB Connector IntegrityError?

2018-03-07 Thread Mike Bayer
On Wed, Mar 7, 2018 at 11:30 AM, KCY wrote: > In one of my tests I'm checking that a pair of (non primary) fields must be > unique. This definition is done with: > > __table_args__ = (UniqueConstraint('entity_id', 'version', > name='id_version_combined_unique'),) > > where `entity_id` is an INT co

[sqlalchemy] Testing against DB Connector IntegrityError?

2018-03-07 Thread KCY
In one of my tests I'm checking that a pair of (non primary) fields must be unique. This definition is done with: __table_args__ = (UniqueConstraint('entity_id', 'version', name= 'id_version_combined_unique'),) where `entity_id` is an INT column referring to a foreign id and version is a plain

Re: [sqlalchemy] Testing custom types

2013-10-01 Thread Michael Bayer
On Oct 1, 2013, at 4:44 PM, Florian Rüchel wrote: > I have created several custom types from base SQLAlchemy types. One example > is a DateTime with integrated timezone support (i.e. it assumes all timezones > are UTC when loading and attaches the tzinfo from pytz to it). Now I want to > test

[sqlalchemy] Testing custom types

2013-10-01 Thread Florian Rüchel
I have created several custom types from base SQLAlchemy types. One example is a DateTime with integrated timezone support (i.e. it assumes all timezones are UTC when loading and attaches the tzinfo from pytz to it). Now I want to test these types. I could just integrate them in my usual tests,

Re: [sqlalchemy] testing for an association proxy (possible bug and patch included)

2013-08-26 Thread Michael Bayer
On Aug 23, 2013, at 6:34 PM, jason kirtland wrote: > > The patch seems like surprising Python behavior to me. Traversing across a > None is almost certainly a bug in regular code, and quashing that error by > default feels dangerous. I would want this to raise by default (and I have > found

Re: [sqlalchemy] testing for an association proxy (possible bug and patch included)

2013-08-23 Thread jason kirtland
On Fri, Aug 23, 2013 at 2:31 PM, Gombas, Gabor (IT) < gabor.gom...@morganstanley.com> wrote: > On Fri, Aug 23, 2013 at 12:11:39PM -0700, Jonathan Vanasco wrote: > > > i think a simple fix could be something like this ( line 240, > sqlalchemy/ext/associationproxy.py > > ) > > > > if self.sc

Re: [sqlalchemy] testing for an association proxy (possible bug and patch included)

2013-08-23 Thread Gombas, Gabor (IT)
On Fri, Aug 23, 2013 at 12:11:39PM -0700, Jonathan Vanasco wrote: > i think a simple fix could be something like this ( line 240, > sqlalchemy/ext/associationproxy.py > ) > > if self.scalar: > -if not getattr(obj, self.target_collection) > -return self._scalar_ge

[sqlalchemy] testing for an association proxy (possible bug and patch included)

2013-08-23 Thread Jonathan Vanasco
I have this general structure: class Person: # orm relationships are preceded by (o)ne or (l)ist o_Person2Address_ActiveShipping = sa.orm.relationship( " Person2Address", primaryjoin="""and_( Person2Address.person_id==Person.id , Person2Address.role_id=='active-shipping' )

Re: [sqlalchemy] Testing sqlalchemy applications :p: :p:

2013-04-25 Thread Paradox
When you say you created a setup fixture but it didn't work, what didn't work exactly? For example, if you just did something like this: def setup(): engine = ... Session = ... session = Session() ...then that won't work because session is a local variable inside the setup fu

Re: [sqlalchemy] Testing sqlalchemy applications :p:

2013-04-23 Thread Simon King
On Tue, Apr 23, 2013 at 2:08 PM, Paradox wrote: > > On 04/23/2013 04:31 PM, Simon King wrote: >> >> On Tue, Apr 23, 2013 at 6:54 AM, Paradox wrote: >>> >>> I have a question related to sqlalchemy and testing, not sure if this is >>> the >>> best place to ask so let me know if I am asking here in

Re: [sqlalchemy] Testing sqlalchemy applications :p:

2013-04-23 Thread Сергей Панов
What do sqlalchemy users usually use for testing? I am willing to learn other ways to do this that are more suited to the packages. thomas we use unittest you can see how to setup session here https://github.com/vice-versa/sacrud/blob/master/sacrud/tests/__init__.py http://pytest.org/lates

Re: [sqlalchemy] Testing sqlalchemy applications :p:

2013-04-23 Thread Paradox
On 04/23/2013 04:31 PM, Simon King wrote: On Tue, Apr 23, 2013 at 6:54 AM, Paradox wrote: I have a question related to sqlalchemy and testing, not sure if this is the best place to ask so let me know if I am asking here in error. I am trying to learn to write and run tests using py.test. Curr

Re: [sqlalchemy] Testing sqlalchemy applications

2013-04-23 Thread Simon King
On Tue, Apr 23, 2013 at 6:54 AM, Paradox wrote: > I have a question related to sqlalchemy and testing, not sure if this is the > best place to ask so let me know if I am asking here in error. > > I am trying to learn to write and run tests using py.test. Currently I am > working on a spreadsheet s

[sqlalchemy] Testing sqlalchemy applications

2013-04-22 Thread Paradox
I have a question related to sqlalchemy and testing, not sure if this is the best place to ask so let me know if I am asking here in error. I am trying to learn to write and run tests using py.test. Currently I am working on a spreadsheet scrapper that gathers data from a directory tree of spr

[sqlalchemy] Re: SQLAlchemy + Testing a webserver using InnoDB fails (MyISAM is okay)

2010-10-04 Thread Conradaroma
Hi Conor, you were totally right in that I have to close the session, and then the objects relating to my InnoDB can be re-queried and they have what I expect. This is kind of a pain, as I'd like to be able to update those objects continuously. I've modified my code so the session closes when I

Re: [sqlalchemy] SQLAlchemy + Testing a webserver using InnoDB fails (MyISAM is okay)

2010-09-29 Thread Conor
On 09/29/2010 01:47 PM, Conradaroma wrote: > Hi, > > I am currently trying to move my DB tables over to InnoDB from MyISAM. > I am having timing issues with requests and cron jobs that are running > on the server that is leading to some errors. I am quite sure that > transaction support will help m

[sqlalchemy] SQLAlchemy + Testing a webserver using InnoDB fails (MyISAM is okay)

2010-09-29 Thread Conradaroma
Hi, I am currently trying to move my DB tables over to InnoDB from MyISAM. I am having timing issues with requests and cron jobs that are running on the server that is leading to some errors. I am quite sure that transaction support will help me with the problem. I am therefore transitioning to In

Re: [sqlalchemy] testing?

2010-04-20 Thread Michael Bayer
Please read the document: http://svn.sqlalchemy.org/sqlalchemy/trunk/README_MOVED_TO_MERCURIAL Harry Percival wrote: > how do I run some self-testing in sqlalchemy? I found this doc, but > it seems to be out of date?? > > http://svn.sqlalchemy.org/sqlalchemy/trunk/README.unittests > > just f

[sqlalchemy] testing?

2010-04-20 Thread Harry Percival
how do I run some self-testing in sqlalchemy? I found this doc, but it seems to be out of date?? http://svn.sqlalchemy.org/sqlalchemy/trunk/README.unittests just for fun, i'm trying to run these tests inside IronPython, so any pointers in that direction would be helpful also.. thx, HP -- You

[sqlalchemy] testing web.py apps, with database

2009-09-17 Thread Sean
Hi, I'm trying to test my web.py app, including its database functionality. I would like to use a test database for this purpose, but it seems like the standard web.py way of doing things is to hardcode the database connection in something like a config.py file. What's the best way to test a we

[sqlalchemy] Testing SQLAlchemy based app? (Tutorial?)

2009-08-13 Thread AF
Hello, I'm writing a basic SQLAlchemy application, and have started to explore the concept of unit testing in general and specifically with nose. Since I am new to both SQLAlchey and nose, I do not know where to start. Right now the app is at the point where: 1) The tables are defined with dec

[sqlalchemy] Testing and version 0.5.4

2009-06-08 Thread Tomas Zulberti
Hi. I am wanting to do some testing of an application that uses SQLAlchemy 0.5.4, but I need to load some initial data to the database. When I searched for this in google, python-fixture appears as the answer. But checking the page of python-fixture it doesn't seems work for 0.5. The question are

[sqlalchemy] Testing the state of an object in a session.

2009-05-01 Thread thatsanicehatyouhave
Hi, Given a session object, is there a way to test if an object in the session is pending (or for that matter, transient, persistent, or detached)? Thanks! Demitri --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Group

[sqlalchemy] Testing SQLAlchemy applications without the database

2009-01-18 Thread Adam Dziendziel
Hello, I'm working on a larger project which is using SQLAlchemy. We started with writing automated tests using an in-memory SQLite database and inserting test data in setUp() then emptying tables in tearDown(). Even though the in-memory SQLite is pretty fast, the process of inserting test data (

[sqlalchemy] Testing for validity of a Connection

2007-08-30 Thread Moshe C.
How can I test whether a connection object is valid and hasn't, for example, been time outed by the server? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sq

[sqlalchemy] Testing Conditions for insertion, and grouping queries together

2007-08-27 Thread Mike Lewis
Hi, I'm new to SQLAlchemy, and I was wondering if there's a way to test a condition while inserting. I'm trying to make my application use as few separate queries at the same time as possible. Here's a couple cases I have had issues with: Inserting something with a unique column if it doesn't e