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

attempted fix for issue with latest pytest-asyncio [WIP] #119

Open
wants to merge 2 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
Empty file modified .github/workflows/tests.yaml
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified CONTRIBUTING.md
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified docs/reference.md
100644 → 100755
Empty file.
Empty file modified pytest_operator/__init__.py
100644 → 100755
Empty file.
27 changes: 14 additions & 13 deletions pytest_operator/plugin.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@ def pytest_runtest_setup(item):
pytest.skip("Skipping deployment because --no-deploy was specified.")


@pytest.fixture(scope="session")
def tmp_path_factory(request):
# Override temp path factory to create temp dirs under Tox env so that
# confined snaps (e.g., charmcraft) can access them.
return pytest.TempPathFactory(
given_basetemp=Path(os.environ["TOX_ENV_DIR"]) / "tmp" / "pytest",
trace=request.config.trace.get("tmpdir"),
_ispytest=True,
retention_count=1,
retention_policy="failed"
)


def check_deps(*deps):
missing = []
for dep in deps:
Expand All @@ -168,25 +181,13 @@ def check_deps(*deps):
)


@pytest.fixture(scope="module")
def event_loop():
"""Create an instance of the default event loop for each test module."""
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close()


# Plugin load order can't be set, replace asyncio directly
pytest_asyncio.plugin.event_loop = event_loop


def pytest_collection_modifyitems(session, config, items):
"""Automatically apply the "asyncio" marker to any async test items."""
for item in items:
is_async = inspect.iscoroutinefunction(getattr(item, "function", None))
has_marker = item.get_closest_marker("asyncio")
if is_async and not has_marker:
item.add_marker("asyncio")
item.add_marker(pytest.mark.asyncio(scope="module"))


@pytest.hookimpl(tryfirst=True, hookwrapper=True)
Expand Down
Empty file modified pytest_operator/shims.py
100644 → 100755
Empty file.
Empty file modified setup.py
100644 → 100755
Empty file.
Empty file modified tests/data/bundle.yaml
100644 → 100755
Empty file.
Empty file modified tests/data/charms/operator-framework/.flake8
100644 → 100755
Empty file.
Empty file modified tests/data/charms/operator-framework/.jujuignore
100644 → 100755
Empty file.
Empty file modified tests/data/charms/operator-framework/charmcraft.yaml
100644 → 100755
Empty file.
Empty file modified tests/data/charms/operator-framework/config.yaml
100644 → 100755
Empty file.
Empty file modified tests/data/charms/operator-framework/metadata.yaml
100644 → 100755
Empty file.
Empty file modified tests/data/charms/operator-framework/requirements.txt
100644 → 100755
Empty file.
Empty file modified tests/data/charms/reactive-framework/config.yaml
100644 → 100755
Empty file.
Empty file modified tests/data/charms/reactive-framework/layer.yaml
100644 → 100755
Empty file.
Empty file modified tests/data/charms/reactive-framework/metadata.yaml
100644 → 100755
Empty file.
Empty file.
Empty file modified tests/data/charms/resourced-charm/metadata.yaml
100644 → 100755
Empty file.
Empty file modified tests/data/etcd_ch_api_response.json
100644 → 100755
Empty file.
Empty file modified tests/data/model-config.yaml
100644 → 100755
Empty file.
Empty file modified tests/data/test_lib/setup.py
100644 → 100755
Empty file.
Empty file modified tests/integration/test_pytest_operator.py
100644 → 100755
Empty file.
8 changes: 8 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest

pytest_plugins = ["pytester"]

@pytest.fixture(autouse=True)
@pytest.mark.asyncio_event_loop
def setup_asyncio_loop():
pass
Empty file modified tests/unit/test_pytest_operator.py
100644 → 100755
Empty file.
Empty file modified tox.ini
100644 → 100755
Empty file.
Loading