Skip to content

Commit

Permalink
Development improvements (#3032)
Browse files Browse the repository at this point in the history
* Use native API and UI for running tests

* Remove obsolete settings

* Fix yum tests

* Fix import issues

* Refactor pytest.ini

* Add download-requirements tests to pytest.ini

* Use default junit_family

* Do not use deprecated distutils package

* Ignore only known warnings

* Fix pylint import issues for download-requirements

* Update py-version

* Fix comment

* Refactor VSCode tasks

* Format tasks.json

* Add "Pylint download-requirements" task
  • Loading branch information
to-bar authored Mar 24, 2022
1 parent 2271dae commit ce6a086
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"davidanson.vscode-markdownlint",
// Python
"ms-python.python",
"littlefoxteam.vscode-python-test-adapter",
// Ruby
"rebornix.Ruby",
"castwide.solargraph",
Expand All @@ -29,6 +28,7 @@
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.ssh,target=/home/vscode/.ssh,type=bind",
],
"settings": {
"python.envFile": "${workspaceFolder}/.devcontainer/python.env",
"python.pythonPath": "/usr/local/bin/python",
},
"remoteUser": "vscode",
Expand Down
5 changes: 5 additions & 0 deletions .devcontainer/python.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# https://code.visualstudio.com/docs/python/environments#_environment-variables

# PYTHONPATH can contain multiple locations separated by os.pathsep: semicolon (;) on Windows and colon (:) on Linux/macOS.
# Invalid paths are ignored. To verify use "python.analysis.logLevel": "Trace".
PYTHONPATH="ansible/playbooks/roles/repository/files/download-requirements:${PYTHONPATH}"
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ unsafe-load-any-extension=no
extension-pkg-allow-list=

# Minimum supported python version
py-version = 3.6
py-version = 3.10


[MESSAGES CONTROL]
Expand Down
1 change: 0 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"davidanson.vscode-markdownlint",
// Python
"ms-python.python",
"littlefoxteam.vscode-python-test-adapter",
// Ruby
"rebornix.Ruby",
"castwide.solargraph",
Expand Down
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
"--rcfile",
"${workspaceFolder}/.pylintrc"
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
"python.pythonPath": "/usr/local/bin/python",
"python.testing.unittestEnabled": false,

// Ruby
"ruby.format": false,
Expand Down
106 changes: 66 additions & 40 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,68 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Pytest",
"type": "shell",
"command": "mkdir -p test_results && pytest --junitxml=${workspaceFolder}/test_results/pytest_results.xml"
},
{
"label": "Pylint junit",
"type": "shell",
"command": "mkdir -p test_results && pylint --rcfile .pylintrc ./cli ./tests --output ${workspaceFolder}/test_results/pylint_results.xml"
},
{
"label": "Pylint terminal",
"type": "shell",
"command": "pylint --rcfile .pylintrc ./cli ./tests --output-format text"
},
{
"label": "Ansible-lint junit",
"type": "shell",
"command": "mkdir -p test_results && ansible-lint --nocolor -q -c .ansible-lint -p ${workspaceFolder}/ansible/playbooks/*.yml > ${workspaceFolder}/test_results/ansiblelint_results.txt ; ansible-lint-to-junit-xml ${workspaceFolder}/test_results/ansiblelint_results.txt > ${workspaceFolder}/test_results/ansiblelint_results.xml"
},
{
"label": "Ansible-lint terminal",
"type": "shell",
"command": "ansible-lint -q -c .ansible-lint -p ${workspaceFolder}/ansible/playbooks/*.yml"
},
{
"label": "Rubocop junit",
"type": "shell",
"command": "mkdir -p test_results && rubocop -c .rubocop.yml --require rubocop/formatter/junit_formatter --format RuboCop::Formatter::JUnitFormatter --out test_results/rubocop_results.xml"
},
{
"label": "Rubocop terminal",
"type": "shell",
"command": "rubocop -c .rubocop.yml"
// See https://go.microsoft.com/fwlink/?LinkId=733558 for the documentation about the tasks.json format
"problemMatcher": [],
"type": "shell",
"version": "2.0.0",
"tasks": [
{
"label": "Ensure test_results directory",
"command": "mkdir -p ${workspaceFolder}/test_results",
"presentation": {
"echo": false,
"reveal": "silent",
"showReuseMessage": false,
}
]
}
},
{
"label": "Pytest",
"command": "pytest --junitxml=${workspaceFolder}/test_results/pytest_results.xml",
"dependsOn": ["Ensure test_results directory"],
"group": "test",
},
{
"label": "Pylint epicli [junit]",
"command": "pylint --rcfile .pylintrc ./cli ./tests --output ${workspaceFolder}/test_results/pylint_results.xml",
"dependsOn": ["Ensure test_results directory"],
"group": "test",
},
{
"label": "Pylint epicli [terminal]",
"command": "pylint --rcfile .pylintrc ./cli ./tests --output-format text",
"group": "test",
},
{
"label": "Pylint download-requirements",
"command": "pylint",
"args": [
"--rcfile", ".pylintrc",
"--output-format", "text",
"./ansible/playbooks/roles/repository/files/download-requirements/download-requirements.py",
"./ansible/playbooks/roles/repository/files/download-requirements/src",
"./ansible/playbooks/roles/repository/files/download-requirements/tests",
],
"group": "test",
},
{
"label": "Ansible-lint [junit]",
"command": "ansible-lint --nocolor -q -c .ansible-lint -p ${workspaceFolder}/ansible/playbooks/*.yml > ${workspaceFolder}/test_results/ansiblelint_results.txt ; ansible-lint-to-junit-xml ${workspaceFolder}/test_results/ansiblelint_results.txt > ${workspaceFolder}/test_results/ansiblelint_results.xml",
"dependsOn": ["Ensure test_results directory"],
"group": "test",
},
{
"label": "Ansible-lint [terminal]",
"command": "ansible-lint -q -c .ansible-lint -p ${workspaceFolder}/ansible/playbooks/*.yml",
"group": "test",
},
{
"label": "Rubocop [junit]",
"command": "rubocop -c .rubocop.yml --require rubocop/formatter/junit_formatter --format RuboCop::Formatter::JUnitFormatter --out test_results/rubocop_results.xml",
"dependsOn": ["Ensure test_results directory"],
"group": "test",
},
{
"label": "Rubocop [terminal]",
"command": "rubocop -c .rubocop.yml",
"group": "test",
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file fixes import issues (like ModuleNotFoundError: No module named 'tests.mocks')
# when discovering or running tests by adding parent directory to sys.path.
# See https://stackoverflow.com/a/50610630/10861750
4 changes: 2 additions & 2 deletions cli/src/helpers/build_io.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import shutil
from distutils import dir_util

from pathlib import Path

from ansible.inventory.manager import InventoryManager
Expand Down Expand Up @@ -147,7 +147,7 @@ def delete_directory(dir_path):


def copy_files_recursively(src, dst):
dir_util.copy_tree(src, dst)
shutil.copytree(src, dst, dirs_exist_ok=True)


def copy_file(src, dst):
Expand Down
9 changes: 7 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# This file should only contain common options (not CI pipeline or IDE specific)
[pytest]
addopts = -x tests/ -p no:warnings
junit_family = xunit1
filterwarnings =
# packaging package is dependency of azure-cli
ignore:The distutils package is deprecated:DeprecationWarning:packaging.tags
testpaths =
tests/unit/
ansible/playbooks/roles/repository/files/download-requirements/tests/

0 comments on commit ce6a086

Please sign in to comment.