Allow Run Configurations from Cursor UI for Pytest

A common use case for any test framework users (my preferred is PyTest), is to run a test from the IDE (PyCharm in this case) and later have the ability to change the configuration of the run in the UI, per test.

Cursor has pytest support, but if you’re using multiple environments to run tests on, you’ll need more granularity. Having this option is better than just running pytest in the command line, because you end up not needing to think about configuring environments as you change between them, per test.

In PyCharm these are called Run Configurations and it would be accessible via the Play button near the test you just ran (which there isn’t any UI/functionality for in Cursor yet altogether - unless I need to configure something differently! If so please let me know). You can then specify the module and the test, modify arguments (as you can already do with Cursor globally for PyTest) and Environment variables all in one place, per test.

If this already exists somewhere and I couldn’t find it, please let me know!

Hmmm…

Does this help:

pytest support in Cursor currently has some limitations compared to PyCharm’s Run Configurations feature. Let me explain the current state and available options:

  1. Current Pytest Support in Cursor:

    • Basic pytest execution is supported through the command line
    • Global pytest arguments can be configured
    • Environment variables can be set workspace-wide
  2. Available Configuration Options (from our workspace settings):

"[python]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
        "source.organizeImports": "explicit"
    }
}
  1. Current Workarounds:
    • Use command line pytest with specific arguments
    • Configure environment variables in the workspace settings
    • Create custom tasks in the workspace configuration

To handle different test configurations currently, you can:

  1. Create Custom Tasks:
"tasks": {
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run Tests - Environment A",
            "type": "shell",
            "command": "pytest",
            "args": [
                "--env=env_a",
                "${file}"
            ]
        },
        {
            "label": "Run Tests - Environment B",
            "type": "shell",
            "command": "pytest",
            "args": [
                "--env=env_b",
                "${file}"
            ]
        }
    ]
}
  1. Use Environment Variables:
"terminal.integrated.env.windows": {
    "PYTEST_ENV": "development",
    "PYTEST_ADDOPTS": "--verbose"
}

The feature request in the forum (Allow Run Configurations from Cursor UI for Pytest) highlights that users want:

  1. Per-test configuration UI similar to PyCharm
  2. Easy environment switching
  3. Test-specific argument configuration
  4. UI integration with play button near tests

Currently, this functionality isn’t available in the Cursor UI, but you can achieve similar results through workspace configuration and custom tasks.