-
Notifications
You must be signed in to change notification settings - Fork 10
Testing
Testing is an essential part of software development to ensure the reliability and stability of your code. In the Learning Observer project, we currently support Python testing, using the pytest framework. This document provides an overview of how the testing framework is used in the project.
We use the pytest framework for Python testing. Pytest is a popular testing framework that simplifies writing and running test cases. It provides powerful features, such as fixtures, parametrized tests, and plugins, to help you test your code efficiently and effectively.
Before writing and running tests, it's essential to set up the testing environment correctly. Here is a step-by-step guide on how to set up the testing environment:
- Install Python dependencies required for the project. You can find these dependencies in the
requirements.txtfile in the project's root directory. - Install the Python packages for the modules you will be testing. In the Learning Observer project, this includes the
writing_observer,lo_dash_react_components^, andwo_highlight_dashboardmodules.
^ This requires node v16 to installed as it needs to build the components during install
To write test cases for your Python code, follow these guidelines:
- Create a
testsdirectory in the module you want to test, if it doesn't already exist. - For each file or functionality you want to test, create a separate test file with a name in the format
test_<filename>.pyortest_<functionality>.py. - Inside each test file, write test functions that test specific aspects of your code. Start each test function's name with
test_to ensure that pytest can discover and run the test.
Once you have written your test cases, you can run them using the pytest command:
pytest <module_directory>For example, to run tests for the wo_highlight_dashboard module, you would run:
pytest modules/wo_highlight_dashboard/To automate testing in your project, you can use GitHub Actions. This allows you to run tests automatically when you push changes to your repository. The provided GitHub Action YAML file sets up a testing environment for the specified Python versions, installs the necessary dependencies, and runs the tests using pytest. You can customize this file to add or modify steps as needed for your project.
If your tests should be automated make sure to provide them as a parameter in the .github/workflows/pytest.yml. While we work on cleaning up the prior testing framework, we only run select tests.
- name: Unit testing with pytest
run: |
pytest modules/wo_highlight_dashboard/Not yet implemented.