Skip to content

Commit

Permalink
fix: Address incompatibility with strict mode for pytest-asyncio in 0…
Browse files Browse the repository at this point in the history
….17.0 and beyond.
  • Loading branch information
DanCardin committed Aug 23, 2022
1 parent 23c2ab2 commit ead7243
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 84 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ jobs:
python-versions: '["3.7", "3.8", "3.9", "3.10"]'
lint: false

test-pytest-asyncio-gt-16:
uses: ./.github/workflows/lint_and_test.yml
with:
install: make install
pytest-asyncio-versions: '["0.19"]'
sqlalchemy-versions: '["1.4.39"]'
python-versions: '["3.7"]'
lint: false

test-no-extras:
uses: ./.github/workflows/lint_and_test.yml
with:
Expand Down
18 changes: 14 additions & 4 deletions .github/workflows/lint_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ on:
default: >-
["1.3.24", "1.4.39"]
description: The sqlalchemy versions to utilize in workflow.
pytest-asyncio-versions:
required: false
type: string
default: >-
["0.16"]
description: The sqlalchemy versions to utilize in workflow.

jobs:
test:
Expand Down Expand Up @@ -64,6 +70,7 @@ jobs:
matrix:
python-version: ${{fromJson(inputs.python-versions)}}
sqlalchemy-version: ${{fromJson(inputs.sqlalchemy-versions)}}
pytest-asyncio-version: ${{fromJson(inputs.pytest-asyncio-versions)}}

steps:
- uses: actions/checkout@v2
Expand All @@ -85,14 +92,17 @@ jobs:
- name: Install dependencies
run: ${{ inputs.install }}

- name: Install dependencies
- name: Install sqlalchemy version
run: pip install 'sqlalchemy==${{ matrix.sqlalchemy-version }}'

- name: Run linters
run: poetry run make lint
- name: Install pytest-asyncio version
run: pip install 'pytest-asyncio==${{ matrix.pytest-asyncio-version }}'

- if: ${{ inputs.lint }}
name: Run tests
name: Run linters
run: poetry run make lint

- name: Run tests
run: ${{ inputs.run }}

- name: Store test result artifacts
Expand Down
103 changes: 27 additions & 76 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pytest-mock-resources"
version = "2.4.4"
version = "2.4.5"
description = "A pytest plugin for easily instantiating reproducible mock resources."
authors = [
"Omar Khan <oakhan3@gmail.com>",
Expand Down Expand Up @@ -62,7 +62,7 @@ mypy = {version = "0.931", python = ">=3.5"}
pydocstyle = {version = "*", python = ">=3.5"}
sqlalchemy-stubs = {version = "*", python = ">=3.5"}
pytest-xdist = "*"
pytest-asyncio = "^0.15.1"
pytest-asyncio = "*"
types-six = "^1.16.0"
types-PyMySQL = "^1.0.2"
types-redis = "^3.5.6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,20 @@ def _sync(pmr_postgres_container, pmr_postgres_config):
engine_manager = _create_engine_manager(pmr_postgres_config)
yield from engine_manager.manage_sync()

@pytest.fixture(scope=scope)
async def _async(pmr_postgres_container, pmr_postgres_config):
engine_manager = _create_engine_manager(pmr_postgres_config)
async for engine in engine_manager.manage_async():
yield engine

if async_:
return _async
# 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 unncessary
# 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._force_asyncio_fixture = True

fixture = pytest.fixture(scope=scope)
return fixture(_async)
else:
return _sync

Expand Down

0 comments on commit ead7243

Please sign in to comment.