Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add flag to clean up postgres databases. #204

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
fail-fast: true
matrix:
# Test our minimum version bound, the highest version available,
# and something in the middle (i.e. what gets run locally).
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog

## [v2.12.0](https://github.com/schireson/pytest-mock-resources/compare/v2.11.0...v2.12.0) (2024-06-19)
## [Unreleased](https://github.com/schireson/pytest-mock-resources/compare/v2.12.0...HEAD) (2024-07-02)

### Features

* Add flag to clean up postgres databases.
([b25714d](https://github.com/schireson/pytest-mock-resources/commit/b25714d3ad2aaca71a810e2468574e00245fc30c))

## [v2.12.0](https://github.com/schireson/pytest-mock-resources/compare/v2.11.0...v2.12.0) (2024-06-20)

### Features

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test-base:
-m 'not postgres and not redshift and not mongo and not redis and not mysql and not moto'

test-parallel:
SQLALCHEMY_WARN_20=1 coverage run -m pytest -n 4 src tests -vv --pmr-multiprocess-safe
SQLALCHEMY_WARN_20=1 coverage run -m pytest -n 4 src tests -vv --pmr-multiprocess-safe --dist=loadfile

test: test-parallel
SQLALCHEMY_WARN_20=1 coverage run -a -m pytest src tests -vv
Expand Down
790 changes: 436 additions & 354 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ filelock = {version = "*", optional = true}
python-on-whales = {version = ">=0.22.0", optional = true}

[tool.poetry.dev-dependencies]
botocore = "1.33.13"
botocore = "1.31.63"
coverage = "*"
moto = ">=2.3.2"
mypy = {version = "0.982"}
mypy = {version = "1.4.0"}
pytest-asyncio = "*"
pytest-order = "^1.2.0"
pytest-xdist = "*"
responses = ">=0.23.0"
ruff = "0.1.15"
Expand Down Expand Up @@ -145,6 +146,7 @@ filterwarnings = [
"ignore:stream argument is deprecated. Use stream parameter in request directly:DeprecationWarning",
"ignore:Boto3 will no longer support Python 3.7.*::boto3",
"ignore:datetime.datetime.utcnow.*:DeprecationWarning",
"ignore:unclosed.*:ResourceWarning",
]

[build-system]
Expand Down
10 changes: 10 additions & 0 deletions src/pytest_mock_resources/compat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import importlib.resources
import sys

from pytest_mock_resources.compat.import_ import ImportAdaptor

# isort: split
Expand Down Expand Up @@ -70,6 +73,13 @@
pymysql = ImportAdaptor("pymysql", "mysql")


def get_resource(package: str) -> str:
if sys.version_info >= (3, 9):
return str(importlib.resources.files(package))

return str(importlib.resources.path(package, "").__enter__())


__all__ = [
"sqlalchemy",
"psycopg2",
Expand Down
6 changes: 4 additions & 2 deletions src/pytest_mock_resources/fixture/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import uuid
from typing import Union

Expand All @@ -12,14 +14,14 @@ def generate_fixture_id(enabled: bool = True, name=""):
return None


def asyncio_fixture(async_fixture, scope="function"):
def asyncio_fixture(async_fixture, scope: Scope = "function", name=None):
# pytest-asyncio in versions >=0.17 force you to use a `pytest_asyncio.fixture`
# call instead of `pytest.fixture`. Given that this would introduce an unnecessary
# dependency on pytest-asyncio (when there are other alternatives) seems less than
# ideal, so instead we can just set the flag that they set, as the indicator.
async_fixture._force_asyncio_fixture = True

fixture = pytest.fixture(scope=scope)
fixture = pytest.fixture(scope=scope, name=name)
return fixture(async_fixture)


Expand Down
Loading
Loading