I'm trying to execute tests defined in test_csconfig.py
from the following dir structure:
# tree .
.
├── CMakeLists.txt
├── healthcheck.conf
├── pki
│ ├── __pycache__
│ │ └── __init__.cpython-37.pyc
│ └── server
│ ├── healthcheck
│ │ ├── core
│ │ │ ├── __init__.py
│ │ │ ├── main.py
│ │ │ └── __pycache__
│ │ │ ├── __init__.cpython-37.pyc
│ │ │ └── main.cpython-37.pyc
│ │ ├── meta
│ │ │ ├── csconfig.py
│ │ │ ├── __init__.py
│ │ │ ├── plugin.py
│ │ │ └── __pycache__
│ │ │ ├── __init__.cpython-37.pyc
│ │ │ └── plugin.cpython-37.pyc
│ │ └── __pycache__
│ └── __pycache__
├── pkihealthcheck.egg-info
│ ├── dependency_links.txt
│ ├── entry_points.txt
│ ├── PKG-INFO
│ ├── SOURCES.txt
│ └── top_level.txt
├── setup.cfg
├── setup.py
└── tests
└── test_csconfig.py
I tried to list the test source directory inside setup.py
, but it doesn't seem to work
setup.py
from setuptools import setup
setup(
# A hyphen ('-') gets converted to underscore ('_') while packaging
# so avoiding the name pki-healthcheck
name='pkihealthcheck',
version='0.1',
packages=[
'pki.server.healthcheck.core',
'pki.server.healthcheck.meta',
],
entry_points={
# creates bin/pki-healthcheck
'console_scripts': [
'pki-healthcheck = pki.server.healthcheck.core.main:main'
],
# register the plugin with ipa-healthcheck
'ipahealthcheck.registry': [
'pkihealthcheck.pki = pki.server.healthcheck.meta.plugin:registry',
],
# register the plugin with pki-healthcheck
'pkihealthcheck.registry': [
'pkihealthcheck.pki = pki.server.healthcheck.meta.plugin:registry',
],
# plugin modules for pkihealthcheck.pki registry
'pkihealthcheck.pki': [
'pki_certs = pki.server.healthcheck.meta.csconfig',
],
},
classifiers=[
'Programming Language :: Python :: 3.6',
],
python_requires='!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*',
setup_requires=['pytest-runner'],
tests_require=['pytest'],
test_suite = 'tests',
)
The setuptools doesn't recognize the tests defined:
# python setup.py test
running pytest
running egg_info
writing pkihealthcheck.egg-info/PKG-INFO
writing dependency_links to pkihealthcheck.egg-info/dependency_links.txt
writing entry points to pkihealthcheck.egg-info/entry_points.txt
writing top-level names to pkihealthcheck.egg-info/top_level.txt
reading manifest file 'pkihealthcheck.egg-info/SOURCES.txt'
writing manifest file 'pkihealthcheck.egg-info/SOURCES.txt'
running build_ext
============================================================================================================ test session starts =============================================================================================================
platform linux -- Python 3.7.7, pytest-4.6.9, py-1.8.0, pluggy-0.12.0
rootdir: /home/dmoluguw/vmworkspace/experiemnts/pki, inifile: tox.ini
plugins: sourceorder-0.5, multihost-3.0
collected 0 items
======================================================================================================== no tests ran in 0.01 seconds ========================================================================================================
As you might note, there are missing __init__.py
under pki
, server
, ... dirs. It's because this is a tool that resides inside a major project. Meddling with them cause the overall project to fail. For more information, you can refer my other question here
I'm pretty sure that I'm missing something obvious but I'm unable to figure it out myself.
Update 1:
I figured out that the top-level tox.ini
was creating the issue. Removing this file let the setuptool to identify the tests.
Update 2:
After adding a new tox.ini to my tool, the pytest is able to find the tests. However, when executing using tox, the module fails
# tox -epy3
ImportError while importing test module '/tmp/workdir/pki/experiemnts/pki/base/server/healthcheck/tests/test_csconfig.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_csconfig.py:11: in <module>
from pki.server.healthcheck.meta.plugin import registry
E ModuleNotFoundError: No module named 'pki.server.healthcheck'
My new tox.ini
:
[tox]
minversion=2.3.1
envlist=py3,flake8,pep8
[testenv]
# sitepackages is needed for ipalib but this confuses the deps for pytest
# pep8 and flake8 so those must be installed globally as well.
sitepackages=True
[testenv:py3]
basepython=python3
commands=
{envpython} -m pytest