Skip to content

Commit

Permalink
Fixed fixture yielding (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfx authored Sep 11, 2024
1 parent 2121929 commit 16d54e9
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 37 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sources = ["src"]
include = ["src"]

[project]
name = "databricks-labs-pytested"
name = "databricks-labs-pytester"
dynamic = ["version"]
description = 'Python Testing for Databricks'
readme = "README.md"
Expand Down
23 changes: 0 additions & 23 deletions src/databricks/labs/pytester/fixtures/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +0,0 @@
from .baseline import ws, make_random
from .compute import make_instance_pool, make_job, make_cluster, make_cluster_policy
from .iam import make_group, make_user
from .notebooks import make_notebook, make_directory, make_repo
from .secrets import make_secret_scope, make_secret_scope_acl
from .wheel import workspace_library

__all__ = [
'ws',
'make_random',
'make_instance_pool',
'make_job',
'make_cluster',
'make_cluster_policy',
'make_group',
'make_user',
'make_notebook',
'make_directory',
'make_repo',
'make_secret_scope',
'make_secret_scope_acl',
'workspace_library',
]
2 changes: 1 addition & 1 deletion src/databricks/labs/pytester/fixtures/baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def inner(**kwargs):
_LOG.debug(f"ignoring error while {name} {some} teardown: {e}")


@pytest.fixture(scope="session")
@pytest.fixture
def ws() -> WorkspaceClient:
"""
Create and provide a Databricks WorkspaceClient object.
Expand Down
8 changes: 4 additions & 4 deletions src/databricks/labs/pytester/fixtures/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def create(*, name: str | None = None, **kwargs):
def cleanup_policy(policy_info):
ws.cluster_policies.delete(policy_info.policy_id)

return factory("cluster policy", create, cleanup_policy)
yield from factory("cluster policy", create, cleanup_policy)


@pytest.fixture
Expand Down Expand Up @@ -113,7 +113,7 @@ def create(
def cleanup_cluster(cluster_info):
ws.clusters.permanent_delete(cluster_info.cluster_id)

return factory("cluster", create, cleanup_cluster)
yield from factory("cluster", create, cleanup_cluster)


@pytest.fixture
Expand Down Expand Up @@ -157,7 +157,7 @@ def create(*, instance_pool_name=None, node_type_id=None, **kwargs):
def cleanup_instance_pool(instance_pool_info):
ws.instance_pools.delete(instance_pool_info.instance_pool_id)

return factory("instance pool", create, cleanup_instance_pool)
yield from factory("instance pool", create, cleanup_instance_pool)


@pytest.fixture
Expand Down Expand Up @@ -215,4 +215,4 @@ def create(**kwargs):
def cleanup_job(job_info):
ws.jobs.delete(job_info.job_id)

return factory("job", create, cleanup_job)
yield from factory("job", create, cleanup_job)
4 changes: 2 additions & 2 deletions src/databricks/labs/pytester/fixtures/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create_user(**kwargs):
def cleanup_user(user_info):
ws.users.delete(user_info.id)

return factory("workspace user", create_user, cleanup_user)
yield from factory("workspace user", create_user, cleanup_user)


def _scim_values(ids: list[str]) -> list[iam.ComplexValue]:
Expand Down Expand Up @@ -93,4 +93,4 @@ def create(
def cleanup_group(group_info):
ws.groups.delete(group_info.id)

return factory("workspace group", create, cleanup_group)
yield from factory("workspace group", create, cleanup_group)
6 changes: 3 additions & 3 deletions src/databricks/labs/pytester/fixtures/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def create(*, path: str | None = None, content: typing.BinaryIO | None = None, *
def cleanup(path):
ws.workspace.delete(path)

return factory("notebook", create, cleanup)
yield from factory("notebook", create, cleanup)


@pytest.fixture
Expand Down Expand Up @@ -92,7 +92,7 @@ def create(*, path: str | None = None):
def cleanup(path):
ws.workspace.delete(path, recursive=True)

return factory("directory", create, cleanup)
yield from factory("directory", create, cleanup)


@pytest.fixture
Expand Down Expand Up @@ -138,4 +138,4 @@ def create(*, url=None, provider=None, path=None, **kwargs):
def cleanup(repo_info):
ws.repos.delete(repo_info.id)

return factory("repo", create, cleanup)
yield from factory("repo", create, cleanup)
25 changes: 23 additions & 2 deletions src/databricks/labs/pytester/fixtures/plugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
import pytest

# pylint: disable=wildcard-import,unused-wildcard-import
from databricks.labs.pytester.fixtures import * # noqa: F403, F401
from databricks.labs.pytester.fixtures.baseline import ws, make_random
from databricks.labs.pytester.fixtures.compute import make_instance_pool, make_job, make_cluster, make_cluster_policy
from databricks.labs.pytester.fixtures.iam import make_group, make_user
from databricks.labs.pytester.fixtures.notebooks import make_notebook, make_directory, make_repo
from databricks.labs.pytester.fixtures.secrets import make_secret_scope, make_secret_scope_acl
from databricks.labs.pytester.fixtures.wheel import workspace_library

__all__ = [
'ws',
'make_random',
'make_instance_pool',
'make_job',
'make_cluster',
'make_cluster_policy',
'make_group',
'make_user',
'make_notebook',
'make_directory',
'make_repo',
'make_secret_scope',
'make_secret_scope_acl',
'workspace_library',
]


def pytest_addoption(parser):
Expand Down
2 changes: 1 addition & 1 deletion src/databricks/labs/pytester/fixtures/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ def cleanup(acl_info):
scope, principal = acl_info
ws.secrets.delete_acl(scope, principal)

return factory("secret scope acl", create, cleanup)
yield from factory("secret scope acl", create, cleanup)

0 comments on commit 16d54e9

Please sign in to comment.