Comments (6)
I dont seem to have any problem flip flopping between template_database=True/False
when using pmr postgres
as the mechanism for spinning up the database, which is really just a simple docker run postgres:<whatever tag>
for the most part.
I thing we should be able to reliably clean up pytest_mock_resource_db_{x}
databases.
Less so template databases, we would need some way to know when to delete the template. I could almost imagine creating a one additional (dynamically created) session scoped fixture per fixture that handled creating the template and cleaning up after it....
from pytest-mock-resources.
Still working through the various CI failures, but I think there's a workable solution here somewhere.
from pytest-mock-resources.
For what it's worth, I regularly use the databases that remain after a given test failure to debug the state of the database at the time of the failure.
What's your usecase for using a docker database that's not managed by PMR itself?
For what it's worth, there is a pmr
utility CLI included with the library which lets you do pmr postgres
to spin up a database out of band from the tests, for reducing initial test startup latency. if that's why.
And for that reason I know it should work with a preexisting database, so it makes me think you might have something else going on in the source db. Can you include the traceback of the failure?
Debugging the reason for the request above aside, I'm not against an enableable feature to delete the databases after the test completes. I dont think that ought to be a problem.
Alternatively or additionally, we could add a pmr postgres --prune-databases
(or the like) helper which basically lists the databases and deletes pytest_mock_resource_db_{x}
matching databases.
Just want to get a sense for whether any particular way would be best for your usecase, given any of the above context
from pytest-mock-resources.
Hey Dan, thanks for getting back to me. We use an existing docker setup to bootstrap the application for testing interactively and development, and to test during CI testing (the reason for that is long-winded, but basically to avoid a docker-in-docker scenario). In CI this isn't an issue since the images are fresh every time.
Personally during development I lean on databases managed by PMR itself (and by extension the tests I write for it), but occasionally I will be doing testing interactively or another member of our team who is already running the application will want to run tests against it. As such this kind of littering isn't a major problem in any way, but it is annoying if you have run say 50 testing runs against your long-running databases since you will end up with 50 templates and 50 databases (which then makes debugging a little challenging since you need to figure out which template and which database to look at).
For the moment, I've added code to our testing suite that cleans up after PMR, deleting all the pytest_mock_resource_db_{x}
and pmr_template_pg_{hash}
databases and templates, but it would be nice if I could just toggle this on, and then toggle it off when I want to debug a failing test case. Doing this is also a little bit non-trivial during testing since you need to be careful about when you attempt to drop tables and when they might be still in use during the lifecycle of the testing framework. Having PMR do it would let you not worry about when the right time to drop the old databases is.
Finally, there is an issue where if you decide to change the configuration of PMR, it will fail with database exists errors if you disable templating after it has been run with it enabled, which feels like it shouldn't happen.
from pytest-mock-resources.
Less so template databases, we would need some way to know when to delete the template. I could almost imagine creating a one additional (dynamically created) session scoped fixture per fixture that handled creating the template and cleaning up after it....
FWIW, that's essentially what I need to do in order to manually clean up after it. I create a session scoped fixture attached to the database root, then once the other engines have been disposed of (this is known in my case since I attach the root database fixture as a dependency on the database engine fixture with the database open), call the cleanup function on the engine which deletes all the databases and templates.
from pytest-mock-resources.
I can't repro the CI test failures locally (and in fact the CI is running the tests twice, so it's succeeding on the first go in CI even...), so that's unfortunate.
Any chance you'd be interested in installing the candidate branch and testing to see if it fully solves your issue in the interim?
from pytest-mock-resources.
Related Issues (20)
- $round operation for MongoDB HOT 2
- SQLAlchemy 2.0 Support HOT 7
- Certain schema DDL is issued only once per test but should be once per metadata
- Dependabot warning for docker subdependency HOT 3
- [Support] Tests hang when using fixture HOT 7
- Error opening connection from redshift_connector HOT 5
- Add in Left/Right UDF's for Redshift HOT 2
- No such event 'before_execute' for target '<sqlalchemy.orm.session.Session object ... HOT 4
- Support SQLAlchemy 1.4 future mode HOT 4
- Dependency on attrs package should be explicit HOT 3
- get_sqlalchemy_engine() not compatible with asyncpg HOT 5
- Allow defining run_args HOT 1
- Getting errors when using `create_redis_fixture` HOT 3
- Missing delete function in redis fixture HOT 1
- Redis Container dont start after update Docker for Desktop on windows. HOT 6
- Allow using `psycopg` instead of `psycopg2` HOT 6
- create_postgres_fixture fails on 2.11.0 HOT 2
- psycopg2-binary is not considered as a suitable driver for Postgres. HOT 2
- Postgres container doesnt start HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytest-mock-resources.