Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves error message when path does not exist #12151

Open
kaddkaka opened this issue Mar 22, 2024 · 2 comments
Open

Improves error message when path does not exist #12151

kaddkaka opened this issue Mar 22, 2024 · 2 comments
Labels
topic: reporting related to terminal output and user-facing messages and errors topic: rewrite related to the assertion rewrite mechanism

Comments

@kaddkaka
Copy link

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
@Zac-HD Zac-HD added topic: reporting related to terminal output and user-facing messages and errors topic: rewrite related to the assertion rewrite mechanism labels Mar 23, 2024
@RonnyPfannschmidt
Copy link
Member

This is a duplicate for More clear output for bound methods

@kaddkaka
Copy link
Author

Thanks, I guess it could also be a further improvement for pathlib, but perhaps pytest is not interested to special case every method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: reporting related to terminal output and user-facing messages and errors topic: rewrite related to the assertion rewrite mechanism
Projects
None yet
Development

No branches or pull requests

3 participants