Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Add notes about where to put unit tests #492

Open
kevinarpe opened this issue Nov 1, 2014 · 3 comments
Open

Request: Add notes about where to put unit tests #492

kevinarpe opened this issue Nov 1, 2014 · 3 comments

Comments

@kevinarpe
Copy link

@kevinarpe kevinarpe commented Nov 1, 2014

I did some Googling. None of the pages have very good explanations of where to put your unit test files.

Also, AFAIK (I am a Python newbiew) there are some drawbacks to <project_root>/test/ about importing. Might need to modify PYTHONPATH during unit test runs.

Also, please talk about why init.py is important for unit tests. A few places recommend it... but I thought it was dead in Python3.

Ref: http://pytest.org/latest/goodpractises.html
Ref: http://stackoverflow.com/questions/5341006/where-should-i-put-tests-when-packaging-python-modules
Ref: http://stackoverflow.com/questions/61151/where-do-the-python-unit-tests-go

@sigmavirus24
Copy link
Contributor

@sigmavirus24 sigmavirus24 commented Nov 1, 2014

@kevinarpe there really isn't one best practice place of locating tests. Several projects do it radically different. Some go so far as to host their tests in an entirely separate repository.

@kaidokert
Copy link

@kaidokert kaidokert commented May 3, 2015

There are some strongly expressed opinions here, specifically "you're going to test the wrong code if you don't test the installed code."
http://blog.ionelmc.ro/2014/05/25/python-packaging/
There is also cookiecutter-pylibrary linked from there that implements this set of best practices

@rileyweber13
Copy link

@rileyweber13 rileyweber13 commented Aug 10, 2018

I'm not sure if this is pertinent, but I didn't want to open a new issue... I'm trying to write tests, and I'm working on this section. In my tests modules, adding from .context import sample give me the following error: ModuleNotFoundError: No module named '__main__.context'; '__main__' is not a package

I have followed the guide exactly, but I can't run my tests! Do you have any tips?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.