PyFacts/tests
2023-08-20 14:18:36 +05:30
..
data Series tests pass data type as string 2022-02-22 13:05:54 +05:30
__init__.py Setup package and tested with tox 2022-02-17 16:20:48 +05:30
conftest.py updated some tests, added test for shrink, not working yet 2023-03-25 18:37:06 +05:30
README.md renamed file 2022-06-26 21:35:23 +05:30
test_core.py tests for sortino and missing frequency 2022-06-12 21:35:13 +05:30
test_pyfacts.py All transform tests are now passing 2023-08-20 14:18:36 +05:30
test_stats.py sortino tests are now passing 2022-09-11 15:13:16 +05:30
test_utils.py improved Readme 2022-06-05 23:12:04 +05:30

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.