Skip to content

Commit 5d2bb34

Browse files
author
Zach Moody
committed
Adds tests for threading
Specifically around duplicate results
1 parent 707a996 commit 5d2bb34

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

tests/integration/conftest.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def id_netbox_service(fixture_value):
357357

358358

359359
@pytest.fixture(scope="session")
360-
def netbox_service(
360+
def docker_netbox_service(
361361
pytestconfig, docker_ip, docker_services, request,
362362
):
363363
"""Get the netbox service to test against.
@@ -411,23 +411,23 @@ def netbox_service(
411411
docker_services.wait_until_responsive(
412412
timeout=300.0, pause=1, check=lambda: netbox_is_responsive(url)
413413
)
414-
nb_api = pynetbox.api(url, token="0123456789abcdef0123456789abcdef01234567")
415414

416415
return {
417416
"url": url,
418417
"netbox_version": netbox_integration_version,
419-
"api": nb_api,
420418
}
421419

422420

423-
@pytest.fixture(scope="session", autouse=True)
424-
def api(netbox_service):
425-
return netbox_service["api"]
421+
@pytest.fixture(scope="session")
422+
def api(docker_netbox_service):
423+
return pynetbox.api(
424+
docker_netbox_service["url"], token="0123456789abcdef0123456789abcdef01234567"
425+
)
426426

427427

428428
@pytest.fixture(scope="session")
429-
def nb_version(netbox_service):
430-
return netbox_service["netbox_version"]
429+
def nb_version(docker_netbox_service):
430+
return docker_netbox_service["netbox_version"]
431431

432432

433433
@pytest.fixture(scope="session")
@@ -469,12 +469,12 @@ def device_role(api):
469469

470470
def pytest_generate_tests(metafunc):
471471
"""Dynamically parametrize some functions based on args from the cli parser."""
472-
if "netbox_service" in metafunc.fixturenames:
473-
# parametrize the requested versions of netbox to the netbox_services fixture
472+
if "docker_netbox_service" in metafunc.fixturenames:
473+
# parametrize the requested versions of netbox to the docker_netbox_services fixture
474474
# so that it will return a fixture for each of the versions requested
475475
# individually rather than one fixture with multiple versions within it
476476
metafunc.parametrize(
477-
"netbox_service",
477+
"docker_netbox_service",
478478
metafunc.config.getoption("netbox_versions"),
479479
ids=id_netbox_service,
480480
indirect=True,

tests/integration/test_dcim.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import pytest
22
from packaging import version
33

4+
import pynetbox
5+
46

57
@pytest.fixture(scope="module")
68
def rack(api, site):
@@ -86,6 +88,27 @@ def init(self, request, site):
8688
endpoint="sites",
8789
)
8890

91+
@pytest.fixture(scope="class")
92+
def add_sites(self, api):
93+
sites = [
94+
api.dcim.sites.create(name="test{}".format(i), slug="test{}".format(i))
95+
for i in range(2, 20)
96+
]
97+
yield
98+
for i in sites:
99+
i.delete()
100+
101+
def test_threading_duplicates(self, docker_netbox_service, add_sites):
102+
api = pynetbox.api(
103+
docker_netbox_service["url"],
104+
token="0123456789abcdef0123456789abcdef01234567",
105+
threading=True,
106+
)
107+
test = api.dcim.sites.all(limit=5)
108+
test_list = list(test)
109+
test_set = set(test_list)
110+
assert len(test_list) == len(test_set)
111+
89112

90113
class TestRack(BaseTest):
91114
@pytest.fixture(scope="class")

0 commit comments

Comments
 (0)