0

I am just using the regular library ( not pytest) and trying to confirm a ValueError.

test:

data = get_time_zone("sun/10-21 tz:US/Eas2tern") 

Result:

if zone not in pytz.all_timezones:
    raise ValueError("Invalid Time Zone Used: " + time_zone)

>>> ValueError: Invalid Time Zone Used: US/Eas2tern

I would like to test it with a similar structure;

Assert "valueError"  etc...
0

1 Answer 1

0

You'll have the easiest time if you use a testing package such as unittest, see this post for how to do that: How do you test that a Python function throws an exception?

But if you don't want to use any testing packages, you can do the following (essentially converting the absence of a ValueError into an AssertionError and doing nothing if you get a ValueError):

def test():
    data = get_time_zone("sun/10-21 tz:US/Eas2tern")

try:
    test()
    raise AssertionError
except ValueError:
    pass
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.