Skip to main content

All Questions

-1 votes
0 answers
28 views

FastAPI dependency is not getting overriden [SOLVED] [closed]

I'm trying to run some tests with pytest against the API but my dependency override is not working. The root app is in my 'main' file and the endpoints are in a 'routers' file. I also have a separate '...
Xcecution's user avatar
  • 1,085
1 vote
2 answers
65 views

How to mock sqlalchemy's async session?

Code snippet from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine engine = create_async_engine(url="") session_maker = async_sessionmaker(engine) How can I mock the ...
Michael Xia's user avatar
0 votes
0 answers
131 views

Python tests failing due to testcontainers-postgres connection refused

I am trying to run integration tests by using PostgresContainer from the testcontainers module in Python. These tests are part of the CI workflow on Github Actions but they are failing due to the ...
Asad Amir Khwaja's user avatar
1 vote
1 answer
449 views

How to get excluded attributes of factory after generation?

I use Factory Boy to generate a fake user. I need a field password that should be hashed (in db, this is the only row related to the password) and a clear_password value in order to know what is the ...
Dorian Turba's user avatar
  • 3,679
0 votes
0 answers
67 views

How to see sql statement in a test that I'm using mock?

I would like to see the raw sql generated by a query in a test where I mocked the db connection. db.py from sqlalchemy import create_engine def get_db(): engine = create_engine('my_db_url_here') ...
RonanFelipe's user avatar
0 votes
1 answer
492 views

testing.postgresql can not initdb

I am trying to create a fastAPI app that connects to a PostgreSQL database when running, but to a testing.postgresql one when running tests. This is my code for the connection: import sqlalchemy ...
HuLu ViCa's user avatar
  • 5,411
2 votes
1 answer
730 views

How should I test db service module with temp database?

I'm looking for the right way to test service module with temporary database. I Have a working example, but I feel like there is a better solution out there this is an example for testing a db_service ...
IlayG01's user avatar
  • 98
0 votes
1 answer
48 views

How to subclass a table by changing the primary columns?

I would like to use SQLAlchemy to add some test fixtures to the database. It should should get or set the value accordingly. I was trying to create a model method like: ProductsModel.ensure(name="...
Nishant's user avatar
  • 21.5k
1 vote
1 answer
5k views

How to mock sqlalchemy execution output inside `with` context manager

I'm trying to write unit tests for my python script which uses sqlalchemy to connect to MySQL. My function looks like this: def check_if_table_exists(db): with db.connect() as cursor: ...
notacorn's user avatar
  • 3,889
0 votes
0 answers
78 views

Getting a textual representation of all the SQL statements executed by SQLAlchemy and psycopg2?

I'm writing an end-to-end regression test for a program that uses SQLAlchemy over psycopg2, as well as psycopg2 directly, to make a set of changes to a database. To test that the program is correct, ...
Dun Peal's user avatar
  • 17.3k
1 vote
1 answer
1k views

Mock default attribute of SQLAlchemy

I have some issues to mock a SQLAlchemy object when using the default and onupdate fields in my models : def get_uuid(): return str(uuid.uuid4()) def get_now(): return db.func.now() class ...
ncrocfer's user avatar
  • 2,562
1 vote
1 answer
941 views

Test where clause in sqlalchemy select object

I am trying to write some functions to build sqlalchemy select statements. For instance: import sqlalchemy as sa from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() ...
RoachLord's user avatar
  • 1,033
1 vote
1 answer
210 views

Flask-SQLAlchemy Unittest Runs Twice

I've set up my project up like this: - proj/ - proj.py - views.py - tests.py - models.py - settings.py - setup.py In proj.py I defined app and db: from flask import Flask from ...
Dash2TheDot's user avatar
1 vote
0 answers
157 views

How to test python database interacting functions

I have some function in my python file course.py which is in proj/com/api/course folder. These function interact with database. I am using flask, sqlalchemy . course.py def create(**kwargs): ...
Suraj's user avatar
  • 170
1 vote
0 answers
1k views

Testing return value of SQLAlchemy parent-child relationship query

Say I have two models set up like so: class ParentFoo(SqlBase): __tablename__ = "parents" id = Column(String, primary_key=True) children = relationship("ChildFoo", backref="parents") class ...
ericso's user avatar
  • 3,288

15 30 50 per page