[PYTHON] About the matter that nosetests does not pass when __init__.py is created in the project directory

Personal notes.

Python Nose Import Error - Stack Overflow

As you can see here If you create __init__.py in the execution directory and project directory, That's the package you should refer to by name (maybe), so

current_dir (__init__.By having py**Package directory**become)
├ __init__.py
├─ lib
│  ├ __init__.py
│  └ bar.py
└─ test_dir
  ├ __init__.py
  └ test_foo.py

If you have a directory structure like this,

$ cd current_dir
$ nosetests test_dir/test_foo.py

To pass through

test_foo.py


from lib import bar
from nose.tools import ok_
ok_(True, False)

Not

test_foo.py


from current_dir.lib import bar
from nose.tools import ok_
ok_(True, False)

I interpreted it as such a story that it would not pass unless it was done.

In python module import,

from .. import foo
from .dir import lib

It is written like this, but basically it is assumed that the directory at runtime is the root. (I want to use sys.path.append properly)

Recommended Posts

About the matter that nosetests does not pass when __init__.py is created in the project directory
Pipfile is not created in the current directory
About the matter that softmax is not needed at the end of Torchvision model.
When the selected object in bpy.context.selected_objects is not returned
About the matter that the contents of Python print are not visible in docker logs
A story that pyenv is stuck because the python execution command PATH does not pass
[Golang] "package exec is not in GOROOT" when executing the test
An error that does not work as expected when calling the tkinter module in a text editor
About the case that the speaker did not make sound in Ubuntu LTS 20.04
[Learning memo] Create if the directory does not exist / Get the files in the directory
Bug that says'val_loss' is not found when using Early Stopping in pytorch-lightning (0.5.3.2)
When the target is Ubuntu 16.04 in Ansible
[pandas] When specifying the default Index label in the at method, "" is not required
It seems that the version of pyflakes is not the latest when flake8 is installed
Talking about the features that pandas and I were in charge of in the project
About the problem that the python version of Google App Engine does not mesh
Solution to the problem that build does not end when installing OpenCV (PEP517)
What to do when the graph does not appear in jupyter (ipython) notebook
Examples and solutions that the Python version specified in pyenv does not run
Deep Learning! The story of the data itself that is read when it does not follow after handwritten number recognition
About the matter that was worried about sampling error
When searching is not working in GAE's Datastore
About the difference between "==" and "is" in python
It is said that libmysqlclient.so.18 does not exist
What to do when is not in the sudoers file.This incident will be reported.
Solve the problem that CSS is not reflected during web application development in Flask
Solved the problem that the image was not displayed in ROMol when loaded with PandasTools.LoadSDF.
There is a pattern that the program did not stop when using Python threading
[Python] Precautions when it does not work even if TimedRotatingFileHandler is set in basicConfig in python2