Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap Unit Test framework #412

Merged
merged 5 commits into from
Mar 2, 2023
Merged

Bootstrap Unit Test framework #412

merged 5 commits into from
Mar 2, 2023

Conversation

arm4b
Copy link
Member

@arm4b arm4b commented Mar 1, 2023

Part of the #286

Based on #411 meeting, we explored adding a unit test framework to the BitOps and setting up first test examples.

This PR adds an initial structure for running the Python unit tests with some basic "hello world" example to start with.

  • Readme
  • VScode settings
  • tox.ini configuration shortcut via tox -e unit run
  • Add to GHA CI
  • sample test_hello.py example
  • add a realistic test related to BitOps codebase

arm4b added 2 commits March 1, 2023 20:21
- Readme
- Vscode settings
- test_hello.py example
- tox.ini configuration via simple `tox -e unit` run
@runforesight
Copy link

runforesight bot commented Mar 1, 2023

Foresight Summary

    
Major Impacts
Foresight hasn't detected any major impact on your workflows and tests.

View More Details

✅  CI workflow has finished in 40 seconds and finished at 1st Mar, 2023.


Job Failed Steps Tests
lint-black -     🔗  N/A See Details
tests-unit -     🔗  N/A See Details
lint-pylint -     🔗  N/A See Details

🔎 See details on Foresight

*You can configure Foresight comments in your organization settings page.

Comment on lines +36 to +43

# Unit tests
# https://docs.python.org/3/library/unittest.html
# Run:
# tox -e unit
[testenv:unit]
commands =
python3 -m unittest discover --verbose --top-level-directory scripts --start-directory scripts/tests/unit --pattern "test_*.py"
Copy link
Member Author

@arm4b arm4b Mar 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out, this part was the hardest that took us a lot of time debugging to make the imports work with the directory structure and tests residing in the scripts/plugins/unit/tests/ directory.

Notice the --top-level-directory scripts and --start-directory scripts/tests/unit parameters.

@arm4b arm4b added this to the v2.5.0 milestone Mar 1, 2023
Comment on lines 1 to 17
// Configuration for running unit tests with the Python extension for VS Code
// https://code.visualstudio.com/docs/python/unit-testing
{
"python.testing.unittestArgs": [
"--verbose",
"--top-level-directory",
"scripts",
"--start-directory",
"./scripts/tests/unit",
"--pattern",
"test_*.py"
],
"python.testing.pytestEnabled": false,
// Uses the unittest module
// https://docs.python.org/3/library/unittest.html
"python.testing.unittestEnabled": true
}
Copy link
Member Author

@arm4b arm4b Mar 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also included the VSCode project-level settings.json.
Should help to get the unit-tests auto-discovered here with zero hassle:
image

Copy link
Contributor

@mcascone mcascone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@arm4b
Copy link
Member Author

arm4b commented Mar 1, 2023

With this setup the imports work fine as we use them in BitOps core, eg. import plugins.config.cli, without using a workaround like import scripts.plugins.config.cli.

Adding the first BitOps-related tests results in an error:

PermissionError: [Errno 13] Permission denied: '/var/logs/bitops'

Path(BITOPS_logging_path).mkdir(parents=True, exist_ok=True)

So it's something to handle in future PRs.

@arm4b arm4b marked this pull request as ready for review March 1, 2023 21:13
@arm4b arm4b mentioned this pull request Mar 1, 2023
9 tasks
@arm4b arm4b merged commit a8e834b into main Mar 2, 2023
@arm4b arm4b deleted the feature/unit-tests branch March 2, 2023 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants