pythonpytestlogfiletox

Export pytest results even when AssertionError


I have a tox file which run pytest on my project and export test results when all of them passed but when one of them failed, and I get an AssertionError, I can not save my logs in my results file. Have you any idea or solution to save logs even when tests failed?


Solution

  • Use the try and except statements to handle exceptions

    Example:

    try:
         #put your pytest stuff here
    except AssertionError:
        pass
    

    If all goes well your log should be saved in no time!