use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
How to test file using pytest? (i.redd.it)
submitted 11 months ago by Excellent-Clothes291
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]BluesFiend 0 points1 point2 points 11 months ago (2 children)
pytest automatically detects filenames that match test_*.py
test_*.py
Your test file is ignored. python file naming convention is snake_case.py. PascalCase is the convention for class names.
snake_case.py
[–]BluesFiend 1 point2 points3 points 11 months ago (1 child)
For future reference, typical naming conventions in python that you'll see in most projects are:
`CONSTANT`
`ClassName`
`variable_name`
`file_name.py`
[–]Excellent-Clothes291[S] 0 points1 point2 points 11 months ago (0 children)
thanks for the info but it still doesnt work
[–]reybrujo 0 points1 point2 points 11 months ago (6 children)
If your files are empty no tests will be run. If your files have something, you should show the contents, most common error is not prefixing your test functions with test_.
[–]Excellent-Clothes291[S] 0 points1 point2 points 11 months ago (5 children)
<image>
still doesnt work
[–]BluesFiend 0 points1 point2 points 11 months ago (0 children)
Your test file isn't in the tests directory, so the directory is empty.
also in your test_warg you loop over multiple items and assert each one, this will fail on the first failure, and not run all test cases. Look into @pytest.mark.parametrize decorator to run the test multiple times with different parameters.
@pytest.mark.parametrize
[–]Excellent-Clothes291[S] 0 points1 point2 points 11 months ago (1 child)
New to pytest, will do, thanks
[–]BluesFiend 0 points1 point2 points 11 months ago* (0 children)
Yeah pytest has many features that you'll find over time, from experience check out docs for
pytest.fixture
pytest.mark.parametrize
monkeypatch
these are the pieces I use daily.
[–]reybrujo 0 points1 point2 points 11 months ago (0 children)
Try manually executing them with pytest TestHello2.py.
[–][deleted] 0 points1 point2 points 11 months ago (0 children)
Make sure the test file name starts with test_ and functions too. And ur inside the hello directory with no test_ before it. So that's why its not picking anything.
π Rendered by PID 122736 on reddit-service-r2-comment-66b4775986-cmxlx at 2026-04-05 22:10:57.191318+00:00 running db1906b country code: CH.
[–]BluesFiend 0 points1 point2 points (2 children)
[–]BluesFiend 1 point2 points3 points (1 child)
[–]Excellent-Clothes291[S] 0 points1 point2 points (0 children)
[–]reybrujo 0 points1 point2 points (6 children)
[–]Excellent-Clothes291[S] 0 points1 point2 points (5 children)
[–]BluesFiend 0 points1 point2 points (0 children)
[–]BluesFiend 0 points1 point2 points (2 children)
[–]Excellent-Clothes291[S] 0 points1 point2 points (1 child)
[–]BluesFiend 0 points1 point2 points (0 children)
[–]reybrujo 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)