Skip to main content
Our localhost system is quite powerful for software development, but is quite cumbersome and difficult to set up. For most solver work, you don’t actually need to set up the localhost just to test out some code.
Keep in mind: The solvers run on AWS in a lambda environment with only the version of Python modules specified in solver/requirements.txt. If your Python environment doesn’t match this exactly, you run the risk of things not working as expected. Pay particular attention to pytest results and always be careful when dealing with new solvers.

Test Your Solver

The solvers all get called through a handle(request) function. You can directly test this function using the same parameters that would come from Calcs.com. To make it work only when you’re developing, you can use if __name__ == "__main__": to begin a short script that will only run when you’re directly running the module (e.g., the play button in VS Code).

Special Consideration: Warnings

Our warnings (the yellow bar that shows up on Calcs.com) need to be initialized before running, otherwise they’ll cause an error. You can initialize them with reset_warnings(), a function in the shared module.

Example (USGS API)

Adding the following bit of code to the bottom of usgs_api.py and hitting the play button in VS Code:
Note the initial reset_warnings() usage

Expected Output

Returns (in the terminal):
This is exactly the value that would be returned from the remote widget in Calcs.com. To test things out, you could paste this in an equation widget and pretend it’s a remote widget.

Make Sure Solver Tests Are Passing

We use pytest to run tests on solver functions. The results are stored in the tests folder with files that begin with the test_ prefix. When creating a PR, Buildkite automatically runs these tests, but you can also run these yourself to quickly check for changes or update values if needed.

Running Tests

  1. Navigate to solver folder - from the dev-environment folder:
  2. Run the tests: To run ALL solver tests:
    To run tests for a specific test file:

Best Practices

  1. Always initialize warnings with reset_warnings() when testing locally
  2. Match your Python environment to solver/requirements.txt as closely as possible
  3. Run pytest regularly to catch any regressions
  4. Test with realistic inputs that match what Calcs.com would send
  5. Use the if __name__ == "__main__": pattern to keep test code separate from production code
This approach allows you to develop and test solvers efficiently without the overhead of setting up the full localhost development environment.