Running unit tests
Setup
Before you run the tests, you need to fire up the MongoDB container. This can be done via the below command:
PORT=1234 docker-compose up -d mongo
The PORT
environment variable will not actually be used, it's just docker-compose
does not realize this variable is not needed if you're only starting the MongoDB service.
Your MongoDB service will be running, and can be reached at port 27018.
Make sure you have a MongoDB service up and running!
Otherwise all the unit tests will fail due to model algorithm timing out!
Run the test
Via command line
poe test
This will run all the unit tests within tests/
directory, which are the files that contain a test_
prefix in their names.
Via VSCode
- Press
ctrl+shift+p
, or go toHelp
>Show All Commands
- Type in
Python: Configure Tests
, select that and then pressenter
- Select
pytest
- Select
tests
- Go to the
testing
panel
If no tests were run before the green ticks will not be there.
To run the tests, right click on the exodus_model_template
symbol, and select Debug Test
.
Write your own test
Most likely you want to make sure your model algorithm can run with some dataset you already have. To test whether your model algorithm can train and predict upon that dataset:
- Create a directory in
tests/datasets
. Let's saytests/datasets/foo/
- Move your training CSV file into
tests/datasets/foo/
, and rename it totests/datasets/foo/train.csv
- Move your prediction CSV file into
tests/datasets/foo/
, and rename it totests/datasets/foo/prediction.csv
- If you have a holdout dataset, move that file into
tests/datasets/foo/
, and rename it totests/datasets/foo/holdout.csv
- Create a new file called
tests/datasets/foo/meta.json
, which should contain the following fields:"target_column_name"
: the name of the target column"features"
: a dict from the column names to the column types. The types should all be either one of"string"
or"double"
- Write the test method by extending the
tests/test_ml.py
files:
It really is as simple as that!def test_foo(): train_predict_delete("./tests/datasets/foo")