-3

i want to make a test function to see if the result from a function returns a dictionary. How would a function with pytest work with this?

Context: The first function is on another file on my computer under the folder called youtube, there is a file called diagnostics.

def test_analisys(entries):
if diagnostics.analisys ...:
    return True
msg = "Type incorrect"
assert diagnostics.analisys(entries, 100000) == 962, msg

this is how my idea would be, test if the function returns a dict, if it doesn't say this message

2
  • You want to check if it's a dictionary and, if not, check that it's equal to the specific tuple (962, "Type incorrect")? What on earth is this function doing that those are the two possibilities? Commented Oct 10, 2021 at 20:03
  • 3
    Does this answer your question? Proper way to assert type of variable in Python Commented Oct 10, 2021 at 20:04

1 Answer 1

0

An easy way to check an object type is the "isinstance" function.

You could use that to check if the return value of a function call is of type dictionary:

assert isinstance(your_function_call(), dict), msg
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.