Skip to content

Utility to run arbitrary commands on a container #93

@n1ngu

Description

@n1ngu

Most projects need some kind of initialization. So far I am copy-pasting this kind of scripts all over the projects

import pytest
import textwrap


@pytest.fixture(scope="session")
def backend_init(docker_services):

    def backend_run(command):
        docker_services._docker_compose.execute(
            "run --rm backend " + textwrap.dedent(command))

    backend_run("python -m django migrate")
    backend_run("python -m django configure")
    backend_run("""\
    bash <<EOF
    set -exo pipefail
    pip install pipenv
    pipenv install --dev --deploy
    python -m django load-fake-data
    EOF
    """)

    return

This sort of works, but I wonder if it would be worth to have some kind of utility to address this kind of need in pytest-docker.

Also, using docker_services._docker_compose.execute feels odd.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions