2

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?

1

1 Answer 1

3

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 install at 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 main to the bottom of your tap.py to make it invocable:
    if __name__ == "__main__":
      TapGoogleAnalytics.cli()
    
  • Install target-jsonl via pipx install target-jsonl or 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}"}
        }
    ]
}
2
  • Thanks to Stéphane Burwash and Pat Nadolny for the sample code, noted the Slack thread mentioned above in Question comments. Apr 16, 2022 at 20:27
  • Another simple thing I can suggest is Directly passing config, state to TapGoogleAnalytics and probably call sync_all on it? If one don't want to modify debug config if they are working on multiple taps, targets or other code
    – rawwar
    Aug 22, 2022 at 1:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.