← Back to team overview

sts-sponsors team mailing list archive

Re: [Merge] ~ack/maas:perftest-create-db-each-test into maas:master

 

+1 with a comment inline.

Diff comments:

> diff --git a/pyproject.toml b/pyproject.toml
> index edf51b0..4f9e548 100644
> --- a/pyproject.toml
> +++ b/pyproject.toml
> @@ -53,3 +53,6 @@ testpaths = [
>    "src/provisioningserver/utils/pytest_tests",
>    # [[[end]]]
>  ]
> +markers = [
> +  'recreate_db: re-create database before each test run'

Let's do this in maastesting.pytest.django:pytest_configure(). That way the module is self-contained.

> +]
> diff --git a/src/maastesting/pytest/django.py b/src/maastesting/pytest/django.py
> index 5848532..b87649b 100644
> --- a/src/maastesting/pytest/django.py
> +++ b/src/maastesting/pytest/django.py
> @@ -169,14 +169,18 @@ def ensuremaasdb(templatemaasdb, pytestconfig, worker_id):
>      database = development.DATABASES["default"]
>      database["NAME"] = dbname
>      cluster = pytestconfig.stash[cluster_stash]
> -    if dbname not in cluster.databases:
> -        template = pytestconfig.stash[db_template_stash]
> -        with cluster.lock.exclusive:
> -            with connect(cluster) as conn:
> -                with conn.cursor() as cursor:
> -                    cursor.execute(
> -                        f'CREATE DATABASE "{dbname}" WITH TEMPLATE "{template}"'
> -                    )
> +    template = pytestconfig.stash[db_template_stash]
> +    with (
> +        cluster.lock.exclusive,
> +        connect(cluster) as conn,
> +        conn.cursor() as cursor,
> +    ):
> +        if list(request.node.iter_markers(name="recreate_db")):

You could use 'request.node.get_closest_marker("recreate_db")'

> +            cursor.execute(f"DROP DATABASE IF EXISTS {dbname}")
> +        if dbname not in cluster.databases:
> +            cursor.execute(
> +                f'CREATE DATABASE "{dbname}" WITH TEMPLATE "{template}"'
> +            )
>      yield
>      database["NAME"] = "no_such_db"
>  


-- 
https://code.launchpad.net/~ack/maas/+git/maas/+merge/433993
Your team MAAS Committers is subscribed to branch maas:master.



References