From 42ba8c1a7301a9382f4973b2d14da7e34002348b Mon Sep 17 00:00:00 2001 From: Richard Zou Date: Thu, 15 Mar 2018 12:06:20 -0400 Subject: [PATCH] Add section on unit testing to CONTRIBUTING (#5813) --- CONTRIBUTING.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3ad384c20c2ab..725a01cb47250 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -72,6 +72,28 @@ For example: You do not need to repeatedly install after modifying python files. +## Unit testing + +PyTorch's testing is located under `test/`. Run the entire test suite with + +``` +python test/run_test.py +``` + +or run individual test files, like `python test/test_nn.py`, for individual test suites. + +### Better local unit tests with pytest +We don't officially support `pytest`, but it works well with our `unittest` tests and offers +a number of useful features for local developing. Install it via `pip install pytest`. + +If you want to just run tests that contain a specific substring, you can use the `-k` flag: + +``` +pytest test/test_nn.py -k Loss -v +``` + +The above is an example of testing a change to Loss functions: this command runs tests such as +`TestNN.test_BCELoss` and `TestNN.test_MSELoss` and can be useful to save keystrokes. ## Writing documentation