Skip to content

Commit

Permalink
Makes pulp_smash a pytest plugin
Browse files Browse the repository at this point in the history
This provides a common place for any pytest fixtures to be added.
  • Loading branch information
bmbouter committed Dec 8, 2021
1 parent 1d53d00 commit b516e90
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
Empty file added pulp_smash/pulp3/conftest.py
Empty file.
7 changes: 7 additions & 0 deletions pulp_smash/pulp3/fixture_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from aiohttp import web


def add_file_system_routes(app, fixtures_root, fixture_name):
fixture_path = fixtures_root / fixture_name
new_routes = [web.static("/", fixture_path.absolute(), show_index=True)]
app.add_routes(new_routes)
54 changes: 54 additions & 0 deletions pulp_smash/pulp3/pytest_plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import asyncio

import pytest

from pulp_smash.api import _get_sleep_time
from pulp_smash.config import get_config
from pulp_smash.pulp3.bindings import delete_orphans

from pulpcore.client.pulpcore import ApiClient, TasksApi


cfg = get_config()
SLEEP_TIME = _get_sleep_time(cfg)


@pytest.fixture(scope="session")
def pulpcore_client():
configuration = cfg.get_bindings_config()
return ApiClient(configuration)


@pytest.fixture(scope="session")
def tasks_api_client(pulpcore_client):
return TasksApi(pulpcore_client)


@pytest.fixture(scope="session")
def async_monitor_task(tasks_api_client):
async def _async_monitor_task(task_href):
completed = ["completed", "failed", "canceled"]
task = tasks_api_client.read(task_href)
while task.state not in completed:
await asyncio.sleep(SLEEP_TIME)
task = tasks_api_client.read(task_href)
return task

return _async_monitor_task


@pytest.fixture
def delete_orphans_pre():
delete_orphans()
yield


@pytest.fixture
def delete_orphans_post():
yield
delete_orphans()


@pytest.fixture
def delete_orphans_pre_post(delete_orphans_pre, delete_orphans_post):
yield
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Framework :: Pytest",
],
packages=find_packages(include=["pulp_smash", "pulp_smash.*"]),
install_requires=[
Expand All @@ -47,6 +48,9 @@
"requests",
"pulpcore-client",
],
entry_points={"console_scripts": ["pulp-smash=pulp_smash.pulp_smash_cli:pulp_smash"]},
entry_points={
"console_scripts": ["pulp-smash=pulp_smash.pulp_smash_cli:pulp_smash"],
"pytest11": ["pulp_smash = pulp_smash.pulp3.pytest_plugin"],
},
test_suite="tests",
)

0 comments on commit b516e90

Please sign in to comment.