Cursor Pytest: PyCharm-Style Test Runner for VS Code & Cursor

Cursor Pytest brings the beloved PyCharm-style inline Run/Debug buttons to VS Code and Cursor, making Python development and testing more intuitive and efficient. Run or debug individual test functions with a single click, just like in JetBrains IDEs!
✨ Features
- Run Test (▶️): Execute individual test functions with one click
- Debug Test (🐞): Debug specific tests with VS Code's integrated debugger
- Configure Args (⚙️): Quick access to pytest argument configuration
📱 Status Bar Integration
- Quick Run/Debug buttons in the status bar for active Python files
- Automatically show/hide based on file type
📁 Python Files Explorer
- Dedicated sidebar view to browse all Python files in your workspace
- Direct run/debug actions from the file tree
- Automatic exclusion of virtual environments
🧪 Test Support
- Pytest Integration: Full support for pytest framework
- Custom Arguments: Configure additional pytest arguments
- VS Code Debugger: Native VS Code debugging without hanging on test failures
- Test Discovery: Automatic detection of test functions using naming conventions
- Right-click context menu options for Python files
- Test-specific menu items when cursor is on test functions
- Quick configuration access
🚀 Installation
From VS Code Marketplace
- Open VS Code or Cursor
- Navigate to Extensions view (
Ctrl+Shift+X
/ Cmd+Shift+X
)
- Search for "Cursor Pytest"
- Click Install
From VSIX File
- Download the latest
.vsix
file from the Releases page
- Open Command Palette (
Ctrl+Shift+P
/ Cmd+Shift+P
)
- Type
Extensions: Install from VSIX...
- Select your downloaded file
📖 Usage
Running Individual Tests
- Open a Python test file (e.g.,
test_example.py
)
- Locate test functions (functions starting with
test_
)
- Click the buttons that appear above each test function:
▶️ Run Test
: Execute the test
🐞 Debug Test
: Debug with breakpoints
⚙️ Pytest Args
: Configure arguments
Status Bar Controls
When a Python file is active, use the status bar buttons:
$(play) Run
: Execute the entire current file
$(bug) Debug
: Debug the entire current file
Python Files Explorer
- Open the Explorer panel
- Find the "Python Files" section
- Browse and click on any Python file to open it
- Use inline run/debug buttons for quick execution
Command Palette
Access all functionality via Command Palette (Ctrl+Shift+P
/ Cmd+Shift+P
):
Run Python File
Debug Python File
Modify Run Configuration...
Modify Additional Pytest Arguments...
⚙️ Configuration
Open VS Code/Cursor settings and search for "Cursor Pytest" or manually edit your settings.json
:
{
"cursor-pytest.pythonPath": "python",
"cursor-pytest.runArgs": [],
"cursor-pytest.additionalArgs": "--alluredir=allure-results -x"
}
Configuration Options
Setting |
Type |
Default |
Description |
cursor-pytest.pythonPath |
string |
"python" |
Path to Python executable |
cursor-pytest.runArgs |
array |
[] |
Arguments for running Python scripts |
cursor-pytest.additionalArgs |
string |
"" |
Additional pytest arguments (e.g., --alluredir=reports -v --tb=short ) |
Example Configurations
Basic pytest with verbose output:
{
"cursor-pytest.additionalArgs": "-v --tb=short"
}
With coverage reporting:
{
"cursor-pytest.additionalArgs": "--cov=src --cov-report=html --cov-report=term"
}
With Allure reporting:
{
"cursor-pytest.additionalArgs": "--alluredir=allure-results -v"
}
🛠️ Requirements
- Python 3.6+ installed and accessible in PATH
- pytest for test execution:
pip install pytest
Optional Dependencies
For enhanced functionality, consider installing:
pip install pytest-cov # Code coverage
pip install pytest-xdist # Parallel test execution
pip install allure-pytest # Allure reporting
🔧 Troubleshooting
Tests Not Detected
- Ensure test functions start with
test_
(e.g., def test_my_function():
)
- Check that pytest is installed:
pip install pytest
- Verify Python path in settings if using virtual environments
Virtual Environment Issues
Set the correct Python path:
{
"cursor-pytest.pythonPath": "/path/to/your/venv/bin/python"
}
Custom Test Discovery
If using custom test patterns, configure pytest in pytest.ini
or pyproject.toml
:
[tool:pytest]
python_files = test_*.py *_test.py
python_functions = test_*
python_classes = Test*
🏗️ Development
Project Structure
.
├── src/
│ └── extension.ts # Main extension logic
├── package.json # Extension manifest
├── tsconfig.json # TypeScript configuration
├── icon.png # Extension icon
└── README.md # This file
Building from Source
Clone the repository:
git clone <repository-url>
cd pycharm-style-runner
Install dependencies:
npm install
Compile TypeScript:
npm run compile
Package the extension:
vsce package
Key Components
- TestCodeLensProvider: Provides inline run/debug buttons above test functions
- PythonFilesProvider: Powers the Python Files explorer tree view
- Status Bar Integration: Manages run/debug buttons in the status bar
- Command Registration: Handles all extension commands and menu items
🛠️ Changelog
v0.3.0 (Latest - Rebranded)
- 🎯 Rebranded: Changed extension name to "Cursor Pytest"
- ✅ Core Features: Run Test, Debug Test, Configure Args
- 🐛 Fixed: Debug hanging completely resolved (no --pdb flag)
- 🚀 Clean UI: Simple, focused interface with essential controls
- ⚡ Fast: Lightweight extension with minimal overhead
Previous Versions (as CurVsTest)
- v0.6.0: Simplified version with core features only
- v0.5.3: Complex test status tracking (removed for simplicity)
- v0.5.2: Debug hanging fixes
- v0.5.1: Enhanced pytest argument integration
- v0.5.0: Initial debug improvements
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Commit your changes:
git commit -m 'Add amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Inspired by the excellent test running experience in JetBrains PyCharm
- Built with the VS Code Extension API
- Uses the pytest framework for test execution
Enjoy a more productive Python testing experience! 🐍✨
For support, feature requests, or bug reports, please visit the GitHub repository or leave a review on the VS Code Marketplace.