Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
pytest-sqlalchemy-mock
Advanced tools
This plugin provides pytest fixtures to create an in-memory DB instance on tests and dump your raw test data.
Python 3.12 or later highly recommended but also might work on Python 3.11.
pip install pytest-sqlalchemy-mock
At the top direcotry,
python3 -m build
python3 -m pip install dist/pytest_sqlalchemy_mock-*.whl
or
python3 -m pip install .
python3 -m pip uninstall pytest_sqlalchemy_mock
Let's assume you have a SQLAlchemy declarative base and some models with it.
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import declarative_base
Base = declarative_base()
class User(Base):
__tablename__ = "user"
id = Column(Integer, primary_key=True)
name = Column(String)
Firstly SQLAlchemy base class which is used for declare models should be passed with sqlalchemy_declarative_base
fixture in conftest.py
@pytest.fixture(scope="function")
def sqlalchemy_declarative_base():
return Base
Then in test functions you can use mocked_session
fixture to make query in mocked DB.
def test_mocked_session_user_table(mocked_session):
user_data = mocked_session.execute("SELECT * from user;").all()
assert user_data == []
Also, you can dump your mock data to DB before start testing via sqlalchemy_mock_config
fixture like following.
@pytest.fixture(scope="function")
def sqlalchemy_mock_config():
return [("user", [
{
"id": 1,
"name": "Kevin"
},
{
"id": 2,
"name": "Dwight"
}
])]
def test_mocked_session_user_class(mocked_session):
user = mocked_session.query(User).filter_by(id=2).first()
assert user.name == "Dwight"
.json
and .csv
FAQs
pytest sqlalchemy plugin for mock
We found that pytest-sqlalchemy-mock demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.