Skip to content

Commit b4e7a17

Browse files
authored
Run tests with PR (KC-244) (#487)
* Add test_imports.py smoke test of keeper imports * Sort setup.py dependencies and add extras_require * Fix setup.py setup formatting * Add Github action workflow for testing with pytest
1 parent 11701a2 commit b4e7a17

File tree

4 files changed

+109
-30
lines changed

4 files changed

+109
-30
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Test with pytest
2+
3+
on: pull_request
4+
5+
env:
6+
PYTHONUNBUFFERED: 1
7+
8+
jobs:
9+
test-with-pytest:
10+
strategy:
11+
matrix:
12+
os: [ubuntu-latest]
13+
python-version: [3.6, 3.9]
14+
15+
runs-on: ${{ matrix.os }}
16+
17+
steps:
18+
- name: Checkout branch
19+
uses: actions/checkout@v2
20+
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v2
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
26+
- name: Install package with test dependencies
27+
run: pip install .[test]
28+
29+
- name: Run import tests
30+
run: pytest tests/test_imports.py

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ norecursedirs = venv
44
# unit-tests/test_login.py fails due to connection errors
55
addopts = --disable-warnings -m "not cross_enterprise" --ignore unit-tests/test_command_utils.py --ignore unit-tests/test_login.py
66
markers =
7+
quicktest: at the moment an alias for the "keeper_imports" marker
8+
keeper_imports: smoke test to make sure all packages and modules in keeper can be imported
79
integration: tests using internal dev.keepersecurity.com test accounts stored in config.json
810
cross_enterprise: created to test a specific issue with cross-enterprise and not normally run

setup.py

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,50 @@
1010
long_description = f.read()
1111

1212
install_requires = [
13+
'asciitree',
1314
'colorama',
1415
'cryptography>=3.4.8',
15-
'pycryptodomex>=3.7.2',
16-
'libkeepass',
17-
'requests',
18-
'tabulate',
1916
'prompt_toolkit>=2.0.4,<=2.0.10',
20-
'asciitree',
2117
'protobuf>=3.13.0',
18+
'pycryptodomex>=3.7.2',
2219
'pyperclip'
20+
'requests',
21+
'tabulate',
2322
]
23+
adpasswd_requires = ['ldap3']
24+
keepass_requires = ['libkeepass']
25+
test_requires = ['pytest', 'testfixtures']
2426

25-
setup(name='keepercommander',
26-
version=keepercommander.__version__,
27-
description='Keeper Commander for Python 3',
28-
long_description=long_description,
29-
long_description_content_type="text/markdown",
30-
author='Craig Lurey',
31-
author_email='[email protected]',
32-
url='https://github.com/Keeper-Security/Commander',
33-
license='MIT',
34-
classifiers=["Development Status :: 4 - Beta",
35-
"License :: OSI Approved :: MIT License",
36-
"Operating System :: OS Independent",
37-
"Programming Language :: Python :: 3.6",
38-
"Topic :: Security"],
39-
keywords='security password',
27+
setup(
28+
name='keepercommander',
29+
version=keepercommander.__version__,
30+
description='Keeper Commander for Python 3',
31+
long_description=long_description,
32+
long_description_content_type="text/markdown",
33+
author='Craig Lurey',
34+
author_email='[email protected]',
35+
url='https://github.com/Keeper-Security/Commander',
36+
license='MIT',
37+
classifiers=["Development Status :: 4 - Beta",
38+
"License :: OSI Approved :: MIT License",
39+
"Operating System :: OS Independent",
40+
"Programming Language :: Python :: 3.6",
41+
"Topic :: Security"],
42+
keywords='security password',
4043

41-
packages=find_packages(),
42-
include_package_data=True,
43-
python_requires='>=3.6',
44-
entry_points={
45-
"console_scripts": [
46-
"keeper=keepercommander.__main__:main",
47-
],
48-
},
49-
install_requires=install_requires
50-
)
44+
packages=find_packages(),
45+
include_package_data=True,
46+
python_requires='>=3.6',
47+
entry_points={
48+
"console_scripts": [
49+
"keeper=keepercommander.__main__:main",
50+
],
51+
},
52+
install_requires=install_requires,
53+
extras_require={
54+
'adpasswd': adpasswd_requires,
55+
'keepass': keepass_requires,
56+
'test': test_requires,
57+
'all': adpasswd_requires + keepass_requires + test_requires
58+
}
59+
)

tests/test_imports.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from pkgutil import walk_packages
2+
from setuptools import find_packages, find_packages
3+
4+
import pytest
5+
6+
import keepercommander
7+
8+
9+
SKIP_PKG_IMPORT = ['keepercommander.yubikey', ]
10+
SKIP_PLUGIN_IMPORT = ['azureadpwd', 'mssql', 'mysql', 'oracle', 'postgresql', 'ssh', 'unixpasswd']
11+
SKIP_PKG_IMPORT += [f'keepercommander.plugins.{p}' for p in SKIP_PLUGIN_IMPORT]
12+
13+
14+
def pkg_import_error(pkg):
15+
if pkg not in SKIP_PKG_IMPORT:
16+
print(f"ERROR: Couldn't import {pkg}")
17+
18+
19+
def get_modules():
20+
return [
21+
m.name for m in
22+
walk_packages(keepercommander.__path__, keepercommander.__name__ + '.', onerror=pkg_import_error)
23+
if m.name not in SKIP_PKG_IMPORT
24+
]
25+
26+
27+
@pytest.mark.quicktest
28+
@pytest.mark.keeper_imports
29+
@pytest.mark.parametrize('pkg_name', [p for p in find_packages() if p not in SKIP_PKG_IMPORT])
30+
def test_keeper_import_pkg(pkg_name):
31+
__import__(pkg_name)
32+
33+
34+
@pytest.mark.quicktest
35+
@pytest.mark.keeper_imports
36+
@pytest.mark.parametrize('module_name', get_modules())
37+
def test_keeper_import_module(module_name):
38+
__import__(module_name)

0 commit comments

Comments
 (0)