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...
Jonas
  • 1,473
  • 2
  • 13
  • 28
AAA
  • 87
  • 1
  • 1
  • 13

1 Answers1

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
Jonas
  • 1,473
  • 2
  • 13
  • 28