pytest
pytest copied to clipboard
Improves error message when path does not exist
When checking assert path.exists(), the output error message becomes very long. Could this be cleaned up and shortened somehow?
test source code:
import pathlib
import unittest
PATH = pathlib.Path(__file__).parent
MY_PATH = pathlib.Path("build_folder") / "tool" / "output" / "result.csv"
def test():
assert MY_PATH.exists()
class TestClass(unittest.TestCase):
@classmethod
def setUpClass(cls):
test_case_path = PATH / "build" / "testcases" / "tmp"
cls.LOG_FILE = test_case_path / "simulation" / "test_log.txt"
def test2(self):
assert self.LOG_FILE.exists()
output:
_________________________________________________________________ test _________________________________________________________________
def test():
> assert MY_PATH.exists()
E AssertionError: assert False
E + where False = <bound method Path.exists of PosixPath('build_folder/tool/output/result.csv')>()
E + where <bound method Path.exists of PosixPath('build_folder/tool/output/result.csv')> = PosixPath('build_folder/tool/output/result.csv').exists
test.py:9: AssertionError
___________________________________________________________ TestClass.test2 ____________________________________________________________
self = <test.TestClass testMethod=test2>
def test2(self):
> assert self.LOG_FILE.exists()
E AssertionError: assert False
E + where False = <bound method Path.exists of PosixPath('/local/david/cs/main/build/testcases/tmp/simulation/test_log.txt')>()
E + where <bound method Path.exists of PosixPath('/local/david/cs/main/build/testcases/tmp/simulation/test_log.txt')> = PosixPath('/local/david/cs/main/build/testcases/tmp/simulation/test_log.txt').exists
E + where PosixPath('/local/david/cs/main/build/testcases/tmp/simulation/test_log.txt') = <test.TestClass testMethod=test2>.LOG_FILE
test.py:21: AssertionError
This is a duplicate for More clear output for bound methods
Thanks, I guess it could also be a further improvement for pathlib, but perhaps pytest is not interested to special case every method