# Pytest Screenshot on Failure
Saves a screenshot when a test case from a pytest execution fails.
## Requirements
This plugin requires that you have an instance of your selenium `WebDriver` being yielded by a `@pytext.fixture`, in
your `conftest.py` file.
This is not just a good practice, but it also helps pytest-screenshot-on-failure to identify your WebDriver instance
for the moment it needs to capture a screenshot.
```python
# conftest.py
from selenium import webdriver
from selenium.webdriver import Chrome
# WebDriver fixture example
@pytest.fixture(scope='session', autouse=True)
def web_driver():
options = webdriver.ChromeOptions()
driver = Chrome(options=options)
yield driver
driver.quit()
```
## How to use
You can enable this plugin by using the `--save_screenshots` flag when running your tests.
Example:
```
python3 -m pytest /tests --save_screenshots
```
The screenshots will be saved by default into the "screenshots" folder. You can change this folder name by using the
flag `--screenshots_dir=<custom_dir_name>`.
Example:
```
python3 -m pytest /tests --save_screenshots --screenshots_dir=images
```
## Screenshots folder structure
* The screenshots from the latest execution will be saved directly on the screenshots root folder, with the date/time
of the execution.
* Give your test file a class name, and the screenshots will be organized by test suite.
* Whenever you star a new execution, older images will be stored in the history folder.
![img.png](images/folder_structure.png)
## Test coverage
The current test coverage rate is **97%**! It's only missing coverage on the `pytest_runtest_makereport` hook.
I couldn't find a way of covering methods that yields a Generator, yet.
```commandline
---------- coverage: platform linux, python 3.10.6-final-0 -----------
Name Stmts Miss Cover Missing
-------------------------------------------------------------------
src/__init__.py 0 0 100%
src/pytest_screenshot_on_failure.py 91 3 97% 80-82
-------------------------------------------------------------------
TOTAL 91 3 97%
```
## Static Analysis & Lint
The repository has no offenses on autoflake, yapf, isort and strict mypy checks. Pending to add CI/CD actions to assert
these checks automatically.
Raw data
{
"_id": null,
"home_page": "https://github.com/kleber26/pytest-screenshot-on-failure",
"name": "pytest-screenshot-on-failure",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "pytest plugin test screenshot",
"author": "Kleber Lauton",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/6b/2d/5698b7dd25fa9a79147575373a799aafcc208f0258995367d32804bf936d/pytest_screenshot_on_failure-1.0.0.tar.gz",
"platform": null,
"description": "# Pytest Screenshot on Failure\nSaves a screenshot when a test case from a pytest execution fails.\n\n## Requirements\nThis plugin requires that you have an instance of your selenium `WebDriver` being yielded by a `@pytext.fixture`, in \nyour `conftest.py` file.\n\nThis is not just a good practice, but it also helps pytest-screenshot-on-failure to identify your WebDriver instance \nfor the moment it needs to capture a screenshot.\n```python\n# conftest.py\nfrom selenium import webdriver\nfrom selenium.webdriver import Chrome\n\n# WebDriver fixture example\n@pytest.fixture(scope='session', autouse=True)\ndef web_driver():\n options = webdriver.ChromeOptions()\n driver = Chrome(options=options)\n \n yield driver\n \n driver.quit()\n```\n\n## How to use\nYou can enable this plugin by using the `--save_screenshots` flag when running your tests. \n\nExample:\n```\npython3 -m pytest /tests --save_screenshots\n```\n\nThe screenshots will be saved by default into the \"screenshots\" folder. You can change this folder name by using the \nflag `--screenshots_dir=<custom_dir_name>`.\n\nExample:\n```\npython3 -m pytest /tests --save_screenshots --screenshots_dir=images\n```\n\n## Screenshots folder structure\n* The screenshots from the latest execution will be saved directly on the screenshots root folder, with the date/time \nof the execution.\n* Give your test file a class name, and the screenshots will be organized by test suite.\n* Whenever you star a new execution, older images will be stored in the history folder.\n\n![img.png](images/folder_structure.png)\n\n## Test coverage\nThe current test coverage rate is **97%**! It's only missing coverage on the `pytest_runtest_makereport` hook. \nI couldn't find a way of covering methods that yields a Generator, yet.\n```commandline\n---------- coverage: platform linux, python 3.10.6-final-0 -----------\nName Stmts Miss Cover Missing\n-------------------------------------------------------------------\nsrc/__init__.py 0 0 100%\nsrc/pytest_screenshot_on_failure.py 91 3 97% 80-82\n-------------------------------------------------------------------\nTOTAL 91 3 97%\n```\n\n## Static Analysis & Lint\nThe repository has no offenses on autoflake, yapf, isort and strict mypy checks. Pending to add CI/CD actions to assert \nthese checks automatically.\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Saves a screenshot when a test case from a pytest execution fails",
"version": "1.0.0",
"project_urls": {
"Download": "https://github.com/kleber26/pytest-screenshot-on-failure/archive/refs/tags/v1.0.0.tar.gz",
"Homepage": "https://github.com/kleber26/pytest-screenshot-on-failure"
},
"split_keywords": [
"pytest",
"plugin",
"test",
"screenshot"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6b2d5698b7dd25fa9a79147575373a799aafcc208f0258995367d32804bf936d",
"md5": "ea3e5e23cb3b1562affc9ee3bd76ab31",
"sha256": "2d03a5253ebfd25ecb9bc1e865eb9959a07ddf194d77b411f812f1a0c775325d"
},
"downloads": -1,
"filename": "pytest_screenshot_on_failure-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "ea3e5e23cb3b1562affc9ee3bd76ab31",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6907,
"upload_time": "2023-07-21T21:38:35",
"upload_time_iso_8601": "2023-07-21T21:38:35.537728Z",
"url": "https://files.pythonhosted.org/packages/6b/2d/5698b7dd25fa9a79147575373a799aafcc208f0258995367d32804bf936d/pytest_screenshot_on_failure-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-21 21:38:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "kleber26",
"github_project": "pytest-screenshot-on-failure",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "pytest-screenshot-on-failure"
}