Skip to content

Commit 9aa3e4e

Browse files
committed
Fix coverage report issue; add --doctest-modules
1 parent 91505bc commit 9aa3e4e

File tree

6 files changed

+67
-66
lines changed

6 files changed

+67
-66
lines changed

pytest.ini

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
[pytest]
22
python_files=tests.py test_*.py
3-
addopts = --ignore=node_modules --ignore=static -r fesxXR
4-
5-
python_paths = ./
6-
7-
flake8-max-line-length = 99
8-
flake8-ignore =
9-
*.py E402 W503
10-
*/migrations/* ALL
11-
*/tests/* ALL
12-
*/deploy/* ALL
13-
*/docs/* ALL
3+
addopts =
4+
-r fesxXR
5+
--doctest-modules

pytest_image_diff/helpers.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
def build_filename(
1313
name: str, suffix: str = "", prefix: str = "", max_length: int = 128
1414
) -> str:
15+
"""
16+
>>> build_filename("name")
17+
'name'
18+
>>> build_filename("name", "suffix", "prefix")
19+
'prefix-name-suffix'
20+
>>> build_filename("loooooooong_nameeeeee", "suffix", max_length=20)
21+
'loooooooo-suffix'
22+
"""
1523
return "-".join(
1624
filter(
1725
None, [prefix, name[: max_length - len(suffix) - len(prefix) - 5], suffix]
@@ -32,9 +40,9 @@ def get_test_info(
3240
request: FixtureRequest, suffix: str = "", prefix: str = ""
3341
) -> "TestInfo":
3442
try:
35-
names = junitxml.mangle_testnames(
43+
names = junitxml.mangle_testnames( # type: ignore
3644
request.node.nodeid.split("::")
37-
) # type: ignore
45+
) #
3846
except AttributeError:
3947
# pytest>=2.9.0
4048
names = junitxml.mangle_test_address(request.node.nodeid)

pytest_image_diff/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .image_diff import _diff
1313

1414
try:
15-
from .splinter import * # noqa
15+
from .splinter import screenshot_regression # noqa
1616
except ImportError:
1717
pass
1818

pytest_image_diff/splinter.py

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,50 @@
88
# Check pytest-splinter
99
from pytest_splinter.plugin import Browser
1010
except ImportError:
11-
raise
12-
13-
from ._types import ImageRegressionCallableType
14-
15-
16-
class ScreenshotRegressionCallableType(Protocol):
17-
def __call__(
18-
self,
19-
browser: Optional[Browser] = None,
20-
threshold: Optional[float] = None,
21-
suffix: Optional[str] = None,
22-
) -> bool:
23-
pass
24-
25-
26-
__all__ = ["screenshot_regression"]
27-
28-
29-
@pytest.fixture(scope="function")
30-
def screenshot_regression(
31-
browser: Browser,
32-
image_regression: ImageRegressionCallableType,
33-
image_diff_threshold: float,
34-
) -> Generator[ScreenshotRegressionCallableType, None, None]:
35-
"""
36-
Check regression browser screenshot
37-
38-
:param browser: optional, by default from `browser` fixture
39-
:param threshold: float, by default from `image_diff_threshold`
40-
:param suffix: str, need for multiple checks by one test
41-
"""
42-
default_browser = browser
43-
44-
def _factory(
45-
browser: Optional[Browser] = None,
46-
threshold: Optional[float] = None,
47-
suffix: Optional[str] = "",
48-
) -> bool:
49-
if browser is None:
50-
browser = default_browser
51-
52-
if threshold is None:
53-
threshold = image_diff_threshold
54-
tf = NamedTemporaryFile(suffix=".png")
55-
image = tf.name
56-
browser.driver.save_screenshot(image)
57-
return image_regression(image, threshold, suffix)
58-
59-
yield _factory
11+
Browser = None
12+
13+
if Browser:
14+
from ._types import ImageRegressionCallableType
15+
16+
class ScreenshotRegressionCallableType(Protocol):
17+
def __call__(
18+
self,
19+
browser: Optional[Browser] = None,
20+
threshold: Optional[float] = None,
21+
suffix: Optional[str] = None,
22+
) -> bool:
23+
pass
24+
25+
__all__ = ["screenshot_regression"]
26+
27+
@pytest.fixture(scope="function")
28+
def screenshot_regression(
29+
browser: Browser,
30+
image_regression: ImageRegressionCallableType,
31+
image_diff_threshold: float,
32+
) -> Generator[ScreenshotRegressionCallableType, None, None]:
33+
"""
34+
Check regression browser screenshot
35+
36+
:param browser: optional, by default from `browser` fixture
37+
:param threshold: float, by default from `image_diff_threshold`
38+
:param suffix: str, need for multiple checks by one test
39+
"""
40+
default_browser = browser
41+
42+
def _factory(
43+
browser: Optional[Browser] = None,
44+
threshold: Optional[float] = None,
45+
suffix: Optional[str] = "",
46+
) -> bool:
47+
if browser is None:
48+
browser = default_browser
49+
50+
if threshold is None:
51+
threshold = image_diff_threshold
52+
tf = NamedTemporaryFile(suffix=".png")
53+
image = tf.name
54+
browser.driver.save_screenshot(image)
55+
return image_regression(image, threshold, suffix)
56+
57+
yield _factory

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ universal = 1
2020

2121
[flake8]
2222
ignore = D203
23-
exclude =
23+
exclude =
2424
.git/,
2525
.tox/,
2626
docs/,

tox.ini

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ changedir = {toxinidir}
99
deps =
1010
-r{toxinidir}/requirements-dev.txt
1111
splinter: -e .[splinter]
12-
12+
setenv =
13+
PYTHONPATH = {toxinidir}
1314
passenv =
1415
CI
1516
TRAVIS
1617
TRAVIS_*
1718

1819
commands =
19-
py.test --basetemp={envtmpdir} -v --cov --cov-report term-missing {posargs}
20+
py.test --basetemp={envtmpdir} -v \
21+
--cov pytest_image_diff \
22+
--cov-report term-missing {posargs}
2023

2124
[testenv:qa]
2225
description = Lint

0 commit comments

Comments
 (0)