1

I have a question that I would like to test a given empty string msg = '' in python unittest but I could not found the right assertion function for it.

I have tried with:

self.assertIsNone(msg)

But I got an error

AssertionError: '' is not None

So I went on with

self.assertIsEmpty(msg)

But I got

object has no attribute 'assertIsEmpty'

Therefore, what is the correct way to check an empty string in unittest? Thanks

1 Answer 1

6

You are looking for

assertEqual(x, '')

Documentation for Python 3

Documentation for Python 2.7

Sign up to request clarification or add additional context in comments.

2 Comments

thanks very much, I just thought it has a specific function for checking empty string.
It's true that some kind of assertIsBlank or assertIsEmptyString does appear in many testing frameworks, but Python's unittest, being built in, is fairly lightweight in this area. Many of the assertions were actually added in Python 2.7. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.