What Python unittest command to run here? - python

Here's my project structure:
├── compute_completeness_service
│ ├── __init__.py
│ ├── app.py
│ ├── tests
│ │ ├── integration
│ │ │ ├── __init__.py
│ │ │ └── test__init__.py
│ │ └── unit
│ │ ├── __init__.py
│ │ ├── __pycache__
│ │ └── test_utils.py
│ └── utils
│ ├── __init__.py
│ └── __pycache__
├── data_quality
│ ├── __init__.py
│ ├── app.py
│ ├── helpers
│ │ ├── __init__.py
│ └── tests
│ └── unit
│ ├── __init__.py
│ ├── __pycache__
│ └── test_helpers.py
I can run these commands from compute_completeness_service and data_quality's root directory:
python3 -m unittest discover -v -s ./compute_completeness_service/tests -p "test_*.py"
python3 -m unittest discover -v -s ./data_quality/tests -p "test_*.py"
but is there one command to run both of them? Because when I run this command, I get no tests:
python3 -m unittest discover -v -t . -p "test_*.py"
----------------------------------------------------------------------
Ran 0 tests in 0.000s
TIA!

Thanks to #MrBean Bremen's comment, I realized that I forgot to add __init__.py to the tests directories
Once added the test discovery worked as expected.

Related

Version on poetry.lock does not match version on GitHub

I have a private repo on GitHub containing a Poetry package which I install with
poetry add git+https://github.com/<USERNAME>/<REPO>.git#<BRANCH>
This project's structure is (assume it's called package_1)
├── README.md
├── package_1
│ ├── __init__.py
│ ├── subpackage_1
│ │ ├── __init__.py
│ │ └── subpackage_1.py
│ ├── subpackage_2
│ │ ├── __init__.py
│ │ └── subpackage_2.py
│ └── subpackage_3
│ ├── __init__.py
│ └── subpackage_3.py
├── poetry.lock
├── pyproject.toml
└── tests
├── __init__.py
└── test_package_1.py
package_1/init.py is just __version__ = "0.3.3"
When I run poetry add git+https://github.com/<USERNAME>/<REPO>.git#<BRANCH> on a new package, the package_1 package is correctly installed but two things happen which I don't understand:
1: The new package's pyproject.toml file shows package_1's version as 0.2.0 when clearly the version is 0.3.3 as mentioned above;
2: The poetry.lock file looks like this after I install package_name
[[package]]
name = "package-name"
version = "0.2.0"
...
Why is the name package-name instead of package_name (notice the _ and -)?

ModuleNotFoundError when trying to run executable created with setuptools

This is my project structure
/Users/tom/PycharmProjects/foo
├── __init__.py
├── foo
│ ├── __init__.py
│ ├── app.py
│ └── run.py
└── setup.py
app.py:
def hello_world():
print("Hello world")
run.py:
from foo.app import hello_world
def main():
hello_world()
setup.py:
from setuptools import setup, find_packages
setup(
name='foo',
version='0.0.1',
packages=find_packages(),
entry_points={
'console_scripts': [
'foo=foo.run:main',
]
}
)
After using pip to install I have the following folder structure:
/Users/tom/Desktop/foo/
├── bin
│ └── foo
├── foo
│ ├── __init__.py
│ ├── app.py
│ └── run.py
└── foo-0.0.1.dist-info
├── INSTALLER
├── METADATA
├── RECORD
├── REQUESTED
├── WHEEL
├── direct_url.json
├── entry_points.txt
└── top_level.txt
When running the executable foo in /bin I am getting the following error:
Traceback (most recent call last):
File "/Users/tom/Desktop/foo/bin/foo", line 5, in <module>
from foo.run import main
ModuleNotFoundError: No module named 'foo'
How can I make the executable work without having to activate a virtual environment and run it from it?
I solved it by changing the import statement in run.py to:
from app import hello_world
And setup.py to:
scripts=['foo/app.py', 'foo/run.py'],
entry_points={
'console_scripts': [
'hello-world=run:main'
]
}
After installing using pip, app.py and run.py are being added to /bin which seems to solve the issue.

use namespace to install package cannot be imported

I have package structure like this:
└── src
├── my_program.py
├── mynamespace-packageone
│   ├── mynamespace
│   │   └── subpackage_one
│   │   ├── __init__.py
│   │   └── first.py
│   ├── mynamespace_packageone.egg-info
│   │   ├── PKG-INFO
│   │   ├── SOURCES.txt
│   │   ├── dependency_links.txt
│   │   └── top_level.txt
│   └── setup.py
└── mynamespace-packagetwo
├── mynamespace
│   └── subpackage_two
│   ├── __init__.py
│   └── second.py
├── mynamespace_packagetwo.egg-info
│   ├── PKG-INFO
│   ├── SOURCES.txt
│   ├── dependency_links.txt
│   └── top_level.txt
└── setup.py
in setup.py in subpackage_one,
from setuptools import setup, find_namespace_packages
PACKAGE = "mynamespace-packageone"
VERSION = "0.1"
setup(
name=PACKAGE,
version=VERSION,
packages=find_namespace_packages(include=["mynamespace.*"]),
description="subpackage_one"
)
in in setup.py in subpackage_two,
from setuptools import setup, find_namespace_packages
PACKAGE = "mynamespace-packagetwo"
VERSION = "0.1"
setup(
name=PACKAGE,
version=VERSION,
packages=find_namespace_packages(include=["mynamespace.*"]),
description="subpackage_two"
)
I use pip to install these two packages in edit mode
pip install -e src/mynamespace-packageone/
pip install -e src/mynamespace-packagetwo/
in my_program.py
I was trying to import mynamespace.subpackage_one
import mynamespace.subpackage_one
but the syntax shows cannot find module mynamespace.
I cannot figure out what is wrong.
Please help.
Thanks,
Arthur

Python can't find self-written module

I'm writing a python module and want to install it. The structure is as follows:
look-up
├── look-up
│ ├── utilities
│ │ ├── __init__.py
│ │ ├── validator.py
│ └── __init__.py
├── README.md
├── requirements.txt
├── setup.py
└── MANIFEST.in
setup.py looks like this:
from setuptools import setup, find_packages
from codecs import open
from os import path
here = path.abspath(path.dirname(__file__))
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
setup(
name = 'look_up',
version = '0.0.1',
packages = find_packages(),
)
Afte i run:
python setup.py develop
and try to import it it I get the error:
No module named 'look_up'
Can someone help me what I'm doing wrong?

Pip fails to install aldryn country segment requirements

I have installed aldryn-segmentation using pip and am trying to install aldryn-country-segment using pip install https://github.com/aldryn/aldryn-country-segment/archive/master.zip as the documentation suggests.
However I get an error that it could not find a version that satisfies the requirement aldryn-geoip.
Collecting aldryn-geoip (from aldryn-country-segment==0.7.2)
Could not find a version that satisfies the requirement aldryn-geoip (from aldryn-country-segment==0.7.2) (from versions: )
No matching distribution found for aldryn-geoip (from aldryn-country-segment==0.7.2)
or when downloading file and running python setup.py install it gives me this: (after lots of other text)
Processing dependencies for aldryn-country-segment==0.7.2
Searching for aldryn-geoip
Reading https://pypi.python.org/simple/aldryn-geoip/
Couldn't find index page for 'aldryn-geoip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
No local packages or download links found for aldryn-geoip
error: Could not find suitable distribution for Requirement.parse('aldryn-geoip')
Is there an obvious workaround to this?
Download and save the file somewhere in your system.
Then unzip it and cd to the directory. You'll get something like this:
.
├── addon.json
├── aldryn_config.py
├── country_segment
│   ├── cms_plugins.py
│   ├── __init__.py │   ├── locale
│   │   └── fr
│   │   └── LC_MESSAGES
│   │   ├── django.mo
│   │   └── django.po
│   ├── middleware
│   │   ├── __init__.py
│   │   └── resolve_country_code_middleware.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   └── __init__.py
│   ├── models.py
│   └── south_migrations
│   ├── 0001_initial.py
│   └── __init__.py
├── LICENSE.txt
├── README.md
├── schemamigration.py
└── setup.py
7 directories, 17 files
Then run sudo python setup.py install and python will install the package to your system.
You may need to install aldryn-geoip as dependency too. (using the same way)

Categories