Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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!

>Solution :

Try making method name and test file starts with test_

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading