-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
155 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"cSpell.words": ["pytest"], | ||
"python.pythonPath": ".venv/bin/python", | ||
"python.testing.pytestEnabled": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
[tool.poetry] | ||
name = "docker-whitelist" | ||
version = "0.0.0" | ||
description = "" | ||
authors = ["Tecnativa"] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.9" | ||
plumbum = "^1.6.9" | ||
|
||
[tool.poetry.dev-dependencies] | ||
black = {version = "^20.8b1", allow-prereleases = true} | ||
flake8 = "^3.8.4" | ||
plumbum = "^1.6.9" | ||
pytest-xdist = "^2.1.0" | ||
|
||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
addopts = -n auto -ra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import logging | ||
from pathlib import Path | ||
|
||
import pytest | ||
from plumbum.cmd import docker | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
def pytest_addoption(parser): | ||
"""Allow prebuilding image for local testing.""" | ||
parser.addoption( | ||
"--prebuild", action="store_true", help="Build local image before testing" | ||
) | ||
parser.addoption( | ||
"--image", | ||
action="store", | ||
default="test:docker-whitelist", | ||
help="Specify testing image name", | ||
) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def image(request): | ||
"""Get image name. Builds it if needed.""" | ||
image = request.config.getoption("--image") | ||
if request.config.getoption("--prebuild"): | ||
build = docker["image", "build", "-t", image, Path(__file__).parent.parent] | ||
retcode, stdout, stderr = build.run() | ||
_logger.log( | ||
# Pytest prints warnings if a test fails, so this is a warning if | ||
# the build succeeded, to allow debugging the build logs | ||
logging.ERROR if retcode else logging.WARNING, | ||
"Build logs for COMMAND: %s\nEXIT CODE:%d\nSTDOUT:%s\nSTDERR:%s", | ||
build.bound_command(), | ||
retcode, | ||
stdout, | ||
stderr, | ||
) | ||
assert not retcode, "Image build failed" | ||
return image |