Napp Test Toggle
VS Code extension that comments out the production client.upload(...) block in a Python script and replaces it with a test block using values read from a JSON file in the project. A second command reverts the operation, removing the test block and restoring the original upload (uncommented).
Commands
Available from the Command Palette (Ctrl+Shift+P / Cmd+Shift+P), the editor context menu (right-click), and as icons in the top-right corner of the editor (when the file is .py):
- Napp: Comment upload and insert TEST — comments out the current
client.upload(...) and inserts the test block.
- Napp: Remove TEST and restore original upload — removes the test block and uncomments the original.
- Napp: Create test configuration file (napp-test-config.json) — creates the configuration file at the project root if it does not already exist.
How It Works
The extension searches the active Python file for the first uncommented client.upload(...) call. It handles nested parentheses, so it works even when multiple arguments are spread across several lines.
When inserting the test, it wraps the original code in markers and comments it out line by line. It then inserts a new client.upload(...) call based on the JSON configuration:
# >>> INIT: origianl >>>
# client.upload(
# store_user='user_example_origianl',
# store_id=125,
# store_password='@#%$V#g3',
# server='server01',
# store_reference='394d5605-f715-4ae1-8acb-f069b15a1ebf',
# )
# <<< END: original <<<
#
# >>> INIT: test >>>
client.upload(
store_user='STORE_USER',
store_id=125,
store_password='STORE_PASS',
server='server',
)
# <<< END: test <<<
When restoring, the extension uses the same markers to remove the test block and uncomment the original block, returning the file to its exact initial state.
Configuration File (napp-test-config.json)
Create a napp-test-config.json file in the project root (the extension searches anywhere in the workspace) with the desired test parameters. Example:
{
"store_user": "store_user",
"store_id": 125,
"store_password": "store_pass",
"server": "server"
}
- Numeric values (such as
store_id) are inserted without quotes.
- String values are inserted using single quotes.
- You can freely add or remove keys (e.g.
store_reference) — all JSON keys become arguments in the test client.upload(...) call.
If the file does not exist, the extension offers to create it automatically with a ready-to-edit example.
Installation (for Your Friends, Without Publishing to the Marketplace)
- Download the generated
.vsix file.
- In VS Code, open the Command Palette and run Extensions: Install from VSIX....
- Select the downloaded
.vsix file.
- Reopen the
.py job file — the buttons will appear in the top-right corner of the editor.
Publishing to the Marketplace (Optional)
If you decide to officially publish the extension:
- Create a publisher account at https://marketplace.visualstudio.com/manage
- Set the
"publisher" field in package.json to your publisher name.
- Install the tool:
npm install -g @vscode/vsce
- Generate a Personal Access Token in Azure DevOps and log in:
vsce login <publisher>
- Publish:
vsce publish
Security Notice
The napp-test-config.json file is stored in your project and may contain test credentials. Avoid committing real passwords — consider adding the file to .gitignore if the repository is shared.