Comments (8)
This is planned.
I have this functionality already written (but commented out) in the conftest.py
, and the settings.py
is set up to read test database variables from the environment :
# Setup the TEST Postgresql database.
test_db_user = "my_db_username"
test_db_password = "Sup3rS3cr3tP455w0rd"
test_db_address = "localhost"
test_db_port = "5432"
test_db_name = "api-template-test"
SQLite is a much easier system to set up as most users don't have a local Postgres database (yes, Docker makes that easier but again not everyone uses, can use, even or wants to use that).
I have been (and still am) concentrating on writing the tests. Once that is done, I will open the option to use Postgres for testing myself 👍
from fastapi-template.
Just an update on this ticket.
I'm working on PR #140, converting the database system to SQLAlchemy ORM (from encode/databases), which seems a better and more maintained way of getting Async database usage. I've also upgraded to SQLAlchemy 2.0, necessitating some fair code changes.
I'm currently working on getting the tests running. When that is merged, I'll back-port the Postgres testing from #125 as well which should finally close this ticket.
from fastapi-template.
I was thinking about this just now as my brain was idling while boiling the kettle.
GitHub has the ability to run a Postgresql service during a GitHub action, so I can update the Tests
Action to create and use this. A simple check in the conftest.py
can detect if running under CI and switch to using that Postgres service.
I prefer to keep the local tests running SQLite by default - all access goes through the same ORM commands regardless of whether we are using Postgres or SQLite. The ORM maintainer updates the relevant driver as needed so there should not be breaking changes (and if so the online CI would catch it). The simple fact is not everyone can run a local Postgresql server or Docker.
However, I also will add an env variable like FORCE_TEST_POSTGRESQL
or whatever that will switch to using Postgresql locally as well and can be picked up by the Docker container.
I also plan to remove all TEST_DB_xxx
variables except the TEST_DB_NAME
, since they should be the same anyway.
Let me know if you see any issues with this, I'll prob get this into a feature branch and PR tomorrow
from fastapi-template.
All the above was easily done, Postgres is working fine on GitHub actions and the tests will use it if in CI or the variable TEST_WITH_POSTGRES
is True.
The issue is that many tests fail (or async hang) under Postgres either locally or remotely. 😭
It is not an issue with the test cases or database incompatibility, but the way I am using async tests with the patched database. Hope to fix this today depending on time.
GitHub has the ability to run a Postgresql service during a GitHub action, so I can update the
Tests
Action to create and use this. A simple check in theconftest.py
can detect if running under CI and switch to using that Postgres service.I prefer to keep the local tests running SQLite by default - all access goes through the same ORM commands regardless of whether we are using Postgres or SQLite. The ORM maintainer updates the relevant driver as needed so there should not be breaking changes (and if so the online CI would catch it). The simple fact is not everyone can run a local Postgresql server or Docker.
However, I also will add an env variable like
FORCE_TEST_POSTGRESQL
or whatever that will switch to using Postgresql locally as well and can be picked up by the Docker container.I also plan to remove all
TEST_DB_xxx
variables except theTEST_DB_NAME
, since they should be the same anyway.
from fastapi-template.
Hey @seapagan, yeah, I remember that, while playing around with tests.
Let me know if you need some help/ideas.
from fastapi-template.
Hey @seapagan, yeah, I remember that, while playing around with tests.
Let me know if you need some help/ideas.
I got sidetracked over the weekend on other projects and also completing #126 and implementing #127 (discussion at #128),
It's prob a simple fix to the get_db
fixture and database provisioning, I hope to get back to this PR soonest.
from fastapi-template.
Another update 😁
GitHub actions are working fine on the 'develop' branch under Postgres. However, the Integration tests are turned off until I fix a few issues (Unit tests ok). I am overhauling the pytest setup/teardown config. I should get that sorted when I have time to work on it.
from fastapi-template.
This has been completed with the 0.5.0
release. closing.
from fastapi-template.
Related Issues (14)
- Internal Links on the web documentation site are broken.
- Advanced User Management HOT 3
- Metrics and Observability endpoints HOT 3
- Key Management secrets engine HOT 1
- Cache Integration HOT 5
- Intermittent test failures with 3.9 and 3.10 HOT 3
- DB Connection / release error HOT 6
- Feature Request: Social Auth HOT 2
- Error when creating user from CLI
- Improvements to the CLI metadata setup
- Projects generated from template fail tests d/t codacy key HOT 2
- Add unit tests HOT 4
- Docker Support 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 fastapi-template.