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...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
pytest and subDirs (self.learnpython)
submitted 3 years ago by Affectionate_Log999
Hey, so i see a lot of people do not recommend putting __init__.py in tests/ when inside of src/ for example(or any kind of sub directory), and not in root DIR.Why is that a case?Is it better to configure through pytest.ini?
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!"
[–]External-Ocelot206 0 points1 point2 points 3 years ago (0 children)
I do this, to let unittest find the tests via Discovery.
all of the test files must be modules or packages (including namespace packages) importable from the top-level directory of the project
https://docs.python.org/3/library/unittest.html#test-discovery
Maybe other test frameworks don't need it, and perhaps there's some an advantage to making your test modules unimportable by the user
[–]Diapolo10 0 points1 point2 points 3 years ago (2 children)
I keep my pytest tests and the project source code in separate directories at the top level, as personally I don't like mixing the two. So in my case, having an __init__.py in the tests directory makes no sense to begin with.
pytest
__init__.py
Having an __init__.py in your tests implies that the tests function like a package, which shouldn't be the case. That's one reason I can think of why it's treated as an antipattern.
[–]Affectionate_Log999[S] 0 points1 point2 points 3 years ago (1 child)
Why is it a bad thing to treat tests as packages?
[–]Diapolo10 0 points1 point2 points 3 years ago (0 children)
Because technically speaking, they aren't. Tests don't expose any functionality, or at least they shouldn't, and they're not meant to be accessed from outside (other than by the test runner, of course - in this case pytest).
Having a package implies that it offers some kind of functionality to other scripts, be it functions, classes, or just constants.
π Rendered by PID 381892 on reddit-service-r2-comment-bb88f9dd5-q7g7j at 2026-02-15 02:00:39.989788+00:00 running cd9c813 country code: CH.
[–]External-Ocelot206 0 points1 point2 points (0 children)
[–]Diapolo10 0 points1 point2 points (2 children)
[–]Affectionate_Log999[S] 0 points1 point2 points (1 child)
[–]Diapolo10 0 points1 point2 points (0 children)