avast / avast/pytest-docker

Fixture `docker_ip` not found

Open
#92 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
489
Forks
77
PR merge metrics
No merged PRs in 30d

Description

Hello,

I'm creating an `http_service` fixture like the one featured in the readme. When I use the fixture, I'm getting `fixture 'docker_ip' not found`.

conftest.py
```
import json
import os
import pytest
import requests
import pathlib
from .utils import is_responsive_404

@pytest.fixture
def tests_dir():
return pathlib.Path(__file__).resolve().parent

@pytest.fixture(scope="session")
def docker_compose_file(pytestconfig):
return pathlib.Path(__file__).resolve().parent / "test-docker-compose.yml"

@pytest.fixture(scope="session")
def http_service(docker_ip, docker_services):
"""
Ensure that Django service is up and responsive.
"""

# `port_for` takes a container port and returns the corresponding host port
port = docker_services.port_for("django", 8000)
url = "http://{}:{}".format(docker_ip, port)
url404 = f"{url}/missing"
docker_services.wait_until_responsive(
timeout=2400.0, pause=0.1, check=lambda: is_responsive_404(url404)
)
return url
```

tests file
```
import json
import pytest
import requests

test_endpoint = "api/"
test_headers = {"Content-Type": "application/json", "Accept": "application/json"}
status = 200

def test_item_list_up(http_service):
"""
Test item list is up
"""
response = requests.get(f"{http_service}/{test_endpoint}item/", headers=test_headers)
resp_data = response.json()
assert response.status_code == status
assert resp_data.get('results', None) != None
assert resp_data.get('pagination', {}).get('totalResults', -1) != -1
```

When I run `pytest -vv` I am getting:
```
ERROR at setup of test_item_list_up
file .../test_item_api.py, line 24
def test_item_list_up(http_service):
file .../tests/conftest.py, line 18
@pytest.fixture(scope="session")
def http_service(docker_ip, docker_services):
E fixture 'docker_ip' not found
> available fixtures: anyio_backend, anyio_backend_name, anyio_backend_options, cache, capfd, capfdbinary, caplog, capsys, capsysbinary, class_mocker, docker_compose_file, doctest_namespace, http_service, mocker, module_mocker, monkeypatch, package_mocker, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, session_mocker, tests_dir, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.
```

Current pip venv:
```
Package Version
------------------ ---------
attrs 21.4.0
bcrypt 4.0.1
certifi 2022.12.7
cffi 1.15.1
charset-normalizer 2.0.12
cryptography 40.0.1
distro 1.8.0
docker 6.0.1
docker-compose 1.29.2
dockerpty 0.4.1
docopt 0.6.2
exceptiongroup 1.1.1
idna 3.4
iniconfig 2.0.0
jsonschema 3.2.0
packaging 23.0
paramiko 3.1.0
pip 21.2.3
pluggy 1.0.0
py 1.11.0
pycparser 2.21
PyNaCl 1.5.0
pyrsistent 0.19.3
pytest 6.2.5
pytest-docker 1.0.1
python-dotenv 0.21.1
PyYAML 5.4.1
requests 2.26.0
setuptools 57.4.0
six 1.16.0
texttable 1.6.7
toml 0.10.2
tomli 2.0.1
urllib3 1.26.15
websocket-client 0.59.0
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.