Handshake
Help Docs
Help Docs
  • PyTest
    • ๐ŸšฅTo Begin With
    • Configuration
    • โ“How To
      • ๐ŸงชAssertions
    • ๐ŸŽHow Does
      • ๐Ÿ“‚Structure
      • ๐ŸŽ‹Fixture
Powered by GitBook
On this page
  • Where you might need:
  • What do we show:
  • To Add Passed Assertions
  • Supported Options:
  • Assert that a certain exception is raised
  1. PyTest
  2. How To

Assertions

Assertion is a way to test the observed results with the expected ones

PreviousHow ToNextHow Does

Last updated 4 months ago

Where you might need:

  • details for the failed assertions

  • passed assertions (may not be for everyone)

  • number of assertions done on a test suite/scenario

What do we show:

  • Number of Assertions passed/failed in a test suite/case

  • Expected Part of the Assertion and Observed Part of the Assertion

  • Details of the Failed Assertion (include stack trace)

To Add Passed Assertions

To save the details of the assertions passed in pytest, please add the enable_assertion_pass_hook as true in your pytest.ini file

[pytest]
enable_assertion_pass_hook=true

Please add this in pytest.ini and this would add details for passed assertions

Supported Options:

Following are the features/ways pytest provides to process assertions and how handshakes report it in db/excel

Assert that a certain exception is raised

# content of test_sysexit.py
import pytest

def f():
    raise SystemExit(1)

def test_mytest():
    with pytest.raises(SystemExit):
        f()

Recommended way to write this case:

# content of test_sysexit.py
import pytest
from handshake.reporters.markers import set_info


def f():
    raise SystemExit(1)


@set_info(
    description="This test would raise the SystemExit Exception if not then it is an error"
)
def test_mytest():
    with pytest.raises(SystemExit):
        f()

If the test passes, refer to the 'description' of the test. If it fails, the details can be found in both the description and the error field of the test case or suite. These are easily identifiable through the generated reports.

[{"name":"Error","message":"@set_info(\n        description=\"This test would raise the SystemExit Exception if not then it is an error\"\n    )\n    def test_mytest():\n>       with pytest.raises(SystemExit):\nE       Failed: DID NOT RAISE <class 'SystemExit'>\n\ntest_sample.py:13: Failed","stack":""}]

Currently, I have not observed pytest to send the details of the passed assertion, when the expected exception was raised inside the test case.

Reference from .

โ“
๐Ÿงช
pytest docs
If not done, no assertions would be saved in TestResults