'How to debug a Singer Tap using VS Code
In creating new Singer Taps using the Meltano SDK, it's not always clear how to setup testing in VS Code.
What's the best way to get the VS Code test features working?
Solution 1:[1]
First Method: Unit testing with VS Code "Tests" pane
This method makes unit tests (pytest tests) easy to run in the VS Code "Tests" pane.
Prereqs:
- Python is installed on your machine.
- The Python VS Code extension is installed.
- You've run
poetry installat least once. - You've set the Python interpreter to the Poetry environment via: "Command Palette" > "Python: Select Interpreter" and then select the matching Poetry environment.
Once the above are complete, the "tests" pane should populate with the list of unit tests and you'll have an option in the VS Code GUI to "Run" or "Debug" each test.
Second Method: Integration test by actually invoking the tap
This method actually runs your tap and sends the output to target-json or a similar sample target.
Prereqs:
- Add a
mainto the bottom of yourtap.pyto make it invocable:if __name__ == "__main__": TapGoogleAnalytics.cli() - Install
target-jsonlviapipx install target-jsonlor similar.
Replace tap_foobar with the actual name of your tap's library and then paste this into VS Code's launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${workspaceRoot}/tap_foobar/tap.py",
"console": "integratedTerminal",
"args": ["--config", ".secrets/config.json", "|", "target-jsonl"],
"env": { "PYTHONPATH": "${workspaceRoot}"}
}
]
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | aaronsteers |
