-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

breidi
  • 1
  • 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? – Silvio Mayolo Oct 10 '21 at 20:03
  • 3
    Does this answer your question? [Proper way to assert type of variable in Python](https://stackoverflow.com/questions/2589522/proper-way-to-assert-type-of-variable-in-python) – joshmeranda Oct 10 '21 at 20:04

1 Answers1

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