Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test helper pytest fixture. #88

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ coverage.xml
*,cover
.hypothesis/
.pytest_cache/
.test_helper_screenshots/

# mypy
.mypy_cache/
Expand Down
45 changes: 45 additions & 0 deletions tests/test_integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,51 @@
from pathlib import Path

import pytest
from dash.testing.composite import DashComposite
from selenium.webdriver.chrome.options import Options


class Helpers:
"""A class to group helpful things when writing tests.

Added as a pytest fixture.

Example
-------
```
def test_my_thing(helpers)
helpers.debug_screenshot()
```
"""

@staticmethod
def debug_screenshot(dash_duo: DashComposite, subdir: str = "") -> None:
"""Save a screenshot of the current state of the testing server.

Useful for debugging and developing tests.
Saves to .test_debug_screenshots or
.test_debug_screenshots/<subdir> if `subdir` is provided.

Parameters
----------
dash_duo : DashComposite
The current dash_duo fixture.
subdir: str, optional
A subdirectory name (to help you find the screenshots.)
"""
screenshots_dirname = Path(".test_helper_screenshots")
if subdir:
screenshots_dirname /= subdir
screenshots_dirname.mkdir(exist_ok=True) # mkdir -p
filename = screenshots_dirname / f"test-{dash_duo.session_id}.png"
dash_duo.driver.save_screenshot(filename.as_posix())


@pytest.fixture
def helpers():
return Helpers


def pytest_setup_options():
options = Options()
options.add_argument("--headless")
Expand Down