> For the complete documentation index, see [llms.txt](https://rahuls-organization-17.gitbook.io/handshake/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rahuls-organization-17.gitbook.io/handshake/help-docs/pytest/how-to/assertions.md).

# Assertions

## 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&#x20;

<figure><img src="/files/1m3CstwxnHxvlMVCJWvc" alt=""><figcaption><p>If not done, no assertions would be saved in TestResults</p></figcaption></figure>

```ini
[pytest]
enable_assertion_pass_hook=true
```

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

> *Reference from* [*pytest docs*](https://docs.pytest.org/en/stable/reference/reference.html#pytest.hookspec.pytest_assertion_pass)*.*

## 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

```python
# 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:

```python
# 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.

```log
[{"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":""}]
```

{% hint style="info" %}
Currently, I have not observed pytest to send the details of the passed assertion, when the expected exception was raised inside the test case.
{% endhint %}
