unit test: Introduce python test for nislsc modules - #63
Conversation
* Add test_command.py for command module * Add test_error.py for error module * Add test_library.py for library module * Add test_property.py for property module * Add test_session.py for session module * Add test_utils.py for utils module --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
* Refactor test name to follow pattern test___<precondition>___<action>___<outcome> --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
* Add tests to increase test coverage for session module --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
* Refactor tests using pytest.mark.parametrize to reduce duplication --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
* Add test___open_device_command_open___close_command___interpreter_close_command_called for command module * Add test___interpreter_available___get_library_version___delegates_to_interpreter for utils module --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
bcfdf5d to
480b8d8
Compare
480b8d8 to
5178e2f
Compare
* Add pytest dependencies * Update python constraints to docs dependencies * Regenerate lock file * Reformat unit test files for styleguide compliance --------- Sign-off-by: zoechanzy <zoe.chan@emerson.com>
5178e2f to
dbd9e8e
Compare
There was a problem hiding this comment.
Pull request overview
Adds a pytest-based unit test suite to validate the generated nislsc Python API surface (largely via interpreter delegation/mocking), and updates Poetry configuration to support running those tests in development.
Changes:
- Added unit tests for
Library,Session,Command,Property,utils, and error/warning types usingpytest+pytest-mock. - Introduced shared test fixtures/helpers (
tests/unit/conftest.py,_session_utils.py) to standardize interpreter/library/session setup. - Added a Poetry
testdependency group (pytest/pytest-mock/pytest-cov) and refreshedpoetry.lock.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_utils.py | Unit tests for utils helpers delegating to the interpreter. |
| tests/unit/test_session.py | Large session API delegation and error/warning behavior tests. |
| tests/unit/test_property.py | Property open/close and property metadata delegation tests. |
| tests/unit/test_library.py | Library lifecycle, language, and error description tests. |
| tests/unit/test_error.py | Error/warning type behavior and formatting tests. |
| tests/unit/test_command.py | Command open/close and command metadata delegation tests. |
| tests/unit/conftest.py | Shared pytest fixtures (mock interpreter, library, session). |
| tests/unit/_session_utils.py | Helper functions for configuring interpreter return values. |
| tests/unit/init.py | Marks unit test package. |
| tests/init.py | Marks tests package. |
| pyproject.toml | Adds test dependency group; refines docs deps python markers. |
| poetry.lock | Lockfile update reflecting new dependency group(s) and resolver output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* Remove flatten and unflatten tests variants in test_utils.py * Remove redundant test in test_command.py * Parametrize tests in test_property.py --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
I would prefer to have the unit test action be enabled here, but I see #64 so it's probably fine. |
|
Personally, I would suggest splitting the refactoring changes in commit |
|
I didn't review all of the new tests in detail but I skimmed them and they look good. Have you been using https://pypi.org/project/pytest-cov/ to verify which methods have test coverage? |
Thanks for the pytest-cov suggestion. It gave me a proper way on checking the test coverage. I think 0% test coverage for generated\nislsc_library_interpreter.py are expected in unit tests because unit tests mock BaseInterpreter instead of importing the ctypes wrapper. nislsc_library_interpreter.py can be tested in system or functional tests with real or simulated devices. 67% for _base_interpreter.py is also expected because abstract pass method bodies are unreachable in unit tests. |

What does this Pull Request accomplish?
Why should this Pull Request be merged?
Add unit test to ensure we have test coverage for slsc modules.
What testing has been done?
Ran unit test locally using

poetry run pytest tests/unit/and all the tests passed.