Skip to content

Commit ee98b8e

Browse files
author
Zach Moody
authored
Merge pull request #315 from raddessi/master.pytest-docker
Integration testing via pytest-docker
2 parents 0ebb64c + 3de7129 commit ee98b8e

File tree

6 files changed

+758
-2
lines changed

6 files changed

+758
-2
lines changed

.github/workflows/py3.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
python-version: ${{ matrix.python }}
2424

2525
- name: Install pynetbox and testing packages.
26-
run: pip install . black==19.10b0 pytest
26+
run: pip install . black==19.10b0 pytest pytest-docker faker
2727

2828
- name: Run Linter
2929
run: black --diff --check pynetbox tests

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,8 @@ ENV/
9696
/site
9797

9898
# mypy
99-
.mypy_cache/
99+
.mypy_cache/
100+
101+
# Other git repos checked out locally
102+
.netbox-docker-*/
103+
.devicetype-library/

tests/conftest.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from packaging import version
2+
3+
4+
DEFAULT_NETBOX_VERSIONS = "2.7, 2.8, 2.9, 2.10"
5+
6+
7+
def pytest_addoption(parser):
8+
"""Hook on the pytest option parser setup.
9+
10+
Add some extra options to the parser.
11+
"""
12+
parser.addoption(
13+
"--netbox-versions",
14+
action="store",
15+
default=DEFAULT_NETBOX_VERSIONS,
16+
help=(
17+
"The versions of netbox to run integration tests against, as a"
18+
" comma-separated list. Default: %s" % DEFAULT_NETBOX_VERSIONS
19+
),
20+
)
21+
22+
parser.addoption(
23+
"--no-cleanup",
24+
dest="cleanup",
25+
action="store_false",
26+
help=(
27+
"Skip any cleanup steps after the pytest session finishes. Any containers"
28+
" created will be left running and the docker-compose files used to"
29+
" create them will be left on disk."
30+
),
31+
)
32+
33+
34+
def pytest_configure(config):
35+
"""Hook that runs after test collection is completed.
36+
37+
Here we can modify items in the collected tests or parser args.
38+
"""
39+
# verify the netbox versions parse correctly and split them
40+
config.option.netbox_versions = [
41+
version.Version(version_string)
42+
for version_string in config.option.netbox_versions.split(",")
43+
]

0 commit comments

Comments
 (0)