Wednesday, 5 October 2022

How to auto email test failures with pytest or other python packages?

I have a page and test class, the test class looks something like below

import unittest
import pytest
import logging

@pytest.mark.usefixtures("setup")
class BigRandomTest(unittest.TestCase):
    log = cl.testogger(logging.DEBUG)

    @pytest.fixture(autouse=True)
    def classSetup(self):
        self.synMax = CarMaxSyndicated()

    # Standard set of tests
    @pytest.mark.run(order=1)
    def test_column_uniqueness_dealership(self):
        pass
        self.log.debug('List of all column duplicate counts: \n' + str(result[1]))
        assert result[0].empty, 'Test failed. Columns with a suspect amount of duplicates: \n {}'.format(result[0])
    
    @pytest.mark.run(order=2)
    def test_column_uniqueness_consistency_dealership(self):
        pass
        self.log.debug('List of all column duplicates differences: \n' + str(result[1]))
        assert result[0].empty, 'Test failed. Columns with significantly different duplicate counts between collections: \n {}'.format(result[0])

when I run the pytest -s -v path_to_test --html=result.html --self-contained-html it generates the report but what I want to do is email the report whenever there is a test failure only, I can setup some stmp or if there is a package that I can use it would be helpful.



from How to auto email test failures with pytest or other python packages?

No comments:

Post a Comment