Browse Source

added testing guidelines

find_closest_changes
Gourav Kumar 2 years ago
parent
commit
a69f3e495e
  1. 2
      setup.py
  2. 42
      tests/testing.md

2
setup.py

@ -9,7 +9,7 @@ setup(
author="Gourav Kumar",
author_email="gouravkr@outlook.in",
url="https://gouravkumar.com",
description="A library to perform financial analytics on Time Series data",
description="A Python library to perform financial analytics on Time Series data",
long_description=open("README.md").read().strip(),
packages=find_packages(),
install_requires=["python-dateutil"],

42
tests/testing.md

@ -0,0 +1,42 @@
# Testing Guidelines
PyFacts uses Pytest for unit testing.
All high level functions are expected to have tests written for them. Each file in the pyfacts module has a dedicated test file. All tests related to that file go within the respective test files.
Since this module needs test data for testing, a Pytest fixture has been defined to generate test data. Use this fixture to generate test data. The fixture uses the random module to generate random test data. A seed has been hardcoded for the random data generator to ensure it generates the same data all the time (if it didn't, tests for specific values would never pass).
WARNING! Do not change the seed for the random data generator. This will cause most tests to fail.
To use the fixture, just pass `create_test_data` as an argument to the test function and then use it within the function. Pytest will automatically locate the relevant function (it need not be imported into the test file).
## Writing tests
Tests are organised as follows:
- Each broad function/method has a Test Class
- All variations should be tested within this class using one or more functions
All test files should be named `test_<module_file_name>.py`.
For instance, test file for `core.py` is named `test_core.py`
All class names should begin with the word `Test`.
All function names should begin with the word `test_`.
It needs to be ensured that all test functions are independent of each other.
## Running tests
Skip this part if you already know how to run pytest.
Open the terminal. Make sure you are in the root pyfacts folder. Then run the following command:
`pytest tests`
This will run the entire test suite. This can take some time depending on the number of tests and speed of your computer. Hence you might want to run only a few tests.
To run tests within a particular file, say test_core.py, type the following command:
`pytest tests/test_core.py`
If you want to run only a particular class within a file, for instance `TestSetitem` within the `test_core.py` file, run them as follows:
`pytest tests/test_core.py::TestSetitem`
This will run only the specified class, making sure your tests don't take too long.
If you're using VS Code, you can make this whole process easier by configuring pytest within VS Code. It will identify all tests and allow you to run them individually from the testing pane on the left.
### Before you push your code
Before you push your code or raise a PR, ensure that all tests are passing. PRs where any of the tests are failing will not be merged. Any modifications to the code which require a modification to existing tests should be accompanied with a note in the PR as to the reasons existing tests had to be modified.
Loading…
Cancel
Save