support assertNotIn for unittest

This commit is contained in:
pikastech 2023-03-26 20:49:10 +08:00
parent 34dedcde2d
commit 07db54e02e
2 changed files with 8 additions and 0 deletions

View File

@ -65,6 +65,10 @@ class TestCase:
def assertIn(self, x, y): def assertIn(self, x, y):
msg = "Expected %r to be in %r" % (x, y) msg = "Expected %r to be in %r" % (x, y)
assert x in y, msg assert x in y, msg
def assertNotIn(self, x, y):
msg = "Expected %r not to be in %r" % (x, y)
assert x not in y, msg
def run(self, result: TestResult, suite_name): def run(self, result: TestResult, suite_name):
for name in dir(self): for name in dir(self):

View File

@ -65,6 +65,10 @@ class TestCase:
def assertIn(self, x, y): def assertIn(self, x, y):
msg = "Expected %r to be in %r" % (x, y) msg = "Expected %r to be in %r" % (x, y)
assert x in y, msg assert x in y, msg
def assertNotIn(self, x, y):
msg = "Expected %r not to be in %r" % (x, y)
assert x not in y, msg
def run(self, result: TestResult, suite_name): def run(self, result: TestResult, suite_name):
for name in dir(self): for name in dir(self):