joeg3
joeg3

Reputation: 185

Unable to assert length of list with Pytest

I am learning Python and I'm using Pytest to check my code as I learn. Here is some sample code I have running:

str = "I love pizza"
str_list = list(str)
print(str_list)
print(len(str_list))

With expected result printed to stdout:

['I', ' ', 'l', 'o', 'v', 'e', ' ', 'p', 'i', 'z', 'z', 'a']
12

But if I run this test:

def create_list_from_string():
    str = "I love pizza"
    str_list = list(str)
    assert 123 == len(str_list)

I cannot get the assert to fail. I have other tests in the file that pass when expected and fail if I purposely edit them to make them fail. So I think I have Pytest set up correctly. I know Python uses indentation for code blocks, and I verified all the indentations are 4 spaces and there's no trailing tabs or spaces. I also know that assert is not broken and I'm making some kind of newbie mistake. Thanks!

Upvotes: 3

Views: 1143

Answers (1)

user10869670
user10869670

Reputation: 106

Try making method name and test file starts with test_

Upvotes: 6

Related Questions