Build Robust Apps with Server Testing

As your app grows, it gets harder to make sure a change in one place hasn’t broken something somewhere else. Tests can help catch these problems before your users do.

With Anvil’s new built-in Server Testing, you can write and run tests for your server code directly inside the Anvil Editor, making it easier than ever to build complex apps with confidence.

Anvil’s Server Testing uses pytest and includes a helpful UI for running tests and viewing output. Server Testing also works from the Anvil CLI so you can keep using your preferred workflow. Read on to learn more about writing and running server tests in Anvil, or check out our quickstart to get started right away:

Testing with pytest

Server Testing in Anvil uses pytest, the most popular Python testing library. So if you’re already familiar with testing in Python, there’s nothing new to learn. Just add Testing to your app, write tests for your server functions in a .py file and click “Run tests”.

Write tests in a .py file and run them from the Anvil Editor

Write tests in a .py file and run them from the Anvil Editor

Run tests directly from the Anvil Editor

You don’t need to leave the Anvil Editor to write and run your server tests because everything is built in. You can write, run and view the output from your tests directly in the Anvil Editor.

The handy Server Tests tab shows you a summary of all the tests you ran, including which ones passed, failed or had errors. You can also click a specific test to see its output.

Test output in the Server Tests tab

Test output in the Server Tests tab

Run tests from your preferred IDE

Do you prefer working from a local IDE? If you’ve synced your app to Anvil using the Anvil CLI, you can still run server tests without using the Anvil Editor. The Anvil CLI allows you to run server tests from your local terminal so you don’t have to interrupt your workflow.

Server tests use their own environment

Server tests run in their own environment with their own databases, so you don’t have to worry about them touching your app’s production environment. You can even set testing-specific values for App Secrets and test functions that send emails without actually sending the email to a recipient.

Ready to get started?

Click the blue plus button in the Sidebar Menu to add Testing to your app and read the documentation to learn more!

Add Testing to your app from the blue plus button

Add Testing to your app from the blue plus button


More about Anvil

If you’re new here, welcome! Anvil is a platform for building full-stack web apps with nothing but Python. No need to wrestle with JS, HTML, CSS, SQL and all their frameworks – just build it all in Python.

Want to build an app of your own? Get started with one of our tutorials: