Unittest file, folder existence check feature

I would like to propose to add new feature to unittest, that can check existence of file or folder.
What are your advices except workarounds? :slight_smile:

import unittest

class TestSomething(unittest.TestCase):
    def test_file_is_installed(self):

There are so many of these, and all are very special purpose. There are
some modules in PyPI providing additional assert* methods, IIRC.

A common approach is to make a mixin class like this:

from os.path import isdir, isfile

class PathTestsMixin:
    def assertIsFolder(self, path, msg="not a folder"):
        return self.assertTrue(isdir(path), msg)
    def assertIsFile(self, path, msg="not a file"):
        return self.assertTrue(isfile(path), msg)

and to define your test class like this:

class TestSomething(unittest.TestCase, PathTestsMixin):

and it will have those methods available. By putting the mixin in a
utility module you can then use it in many test files.

Cameron Simpson cs@cskk.id.au

@cameron thanks for reply. For now i am using Mixins for custom asserts. i thought maybe it could be useful to make this features available in unittest.