Hello! :wave: I’m finishing up development of a ne...
# singer-tap-development
j
Hello! 👋 I’m finishing up development of a new (soon to be) public tap for openexchangerates using the Meltano SDK, and I had a question about testing. When creating a tap with the newest version of the SDK, it creates a
test_core.py
which contains the following snippet which runs the built-in tests along with any custom suites:
Copy code
# Run standard built-in tap tests from the SDK:
TestTapopenexchangerates = get_tap_test_class(
    tap_class=Tapopenexchangerates,
    config=SAMPLE_CONFIG,
    custom_suites=[tap_stream_test_suite, tap_tap_test_suite]
)
If live credentials are supplied as SAMPLE_CONFIG, the tests run as expected but hit an actual endpoint ($$). Obviously, I’ve like to mock responses so that fake credentials can be used. I’ve tried placing the above code block in scope of a requests mock in the hope that all the underlying requests would be mocked, including using the requests-mock package to do so, but I can’t seem to have the underlying requests pick up the mock. Am I making a mistake due to a fundamental misunderstanding of how this is supposed to work? Has anyone run into a similar issue? Tried searching through the messages in this channel but couldn’t find much. Thanks!
e
Hi James! I use the
responses
library in tap-dbt to mock the API responses: https://github.com/MeltanoLabs/tap-dbt/blob/main/tests/test_core.py
j
Thanks for this, Edgar! This example assumes that we’re using the legacy
get_standard_tap_tests
method; I suppose there’s no way to use the newer method in the same way? If not, I’ll try to disregard the newer methods and run it like the legacy style like you have.
e
You could still use the newer framework, doing something like
Copy code
_TestTapDBT = get_tap_test_class(TapDBT, config=SAMPLE_CONFIG)

class TestTapDBT(_TestTapDBT):
    @pytest.fixture(autouse=True)
    @responses.activate
    def _responses(self):
        responses.add_passthru(re.compile("<https://raw.githubusercontent.com/>\\w+"))
        ...
cc @ken_payne