Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Question: "Unknown MySQL server host 'mysql'" error for every test in GitHub Actions #791

Closed
alex-shef opened this issue Mar 24, 2025 · 1 comment

Comments

@alex-shef
Copy link

alex-shef commented Mar 24, 2025

What are you trying to do?

conftest.py:

@pytest.fixture(scope="session")
def mysql_container():
    mysql = MySqlContainer("mysql:9").with_env("MYSQL_ROOT_PASSWORD", "root")
    with mysql:
        yield mysql


@pytest.fixture(scope="module", autouse=True)
def setup_database(mysql_container, django_db_blocker):
    settings.DATABASES["default"]["HOST"] = mysql_container.get_container_host_ip()
    settings.DATABASES["default"]["PORT"] = mysql_container.get_exposed_port(3306)

Runtime environment

github_actions.yml

      - name: Pytest
        uses: pavelzw/pytest-action@v2
        with:
          verbose: true
          emoji: false
          job-summary: false
          custom-pytest: PYTHONPATH=. poetry run pytest

django.db.utils.OperationalError: (2005, "Unknown MySQL server host 'mysql' (-3)")

Everything is working on the local machine. How to do this correctly in GitHub Actions?

@alex-shef
Copy link
Author

It was necessary to create the database separately.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant