Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking libraries #28

Closed
consal opened this issue Nov 11, 2019 · 1 comment
Closed

Mocking libraries #28

consal opened this issue Nov 11, 2019 · 1 comment

Comments

@consal
Copy link

consal commented Nov 11, 2019

Hi,

I have a question - how can I mock something that I test via script_runner?
I know it's meant for integration tests, but sometimes it's useful...

I mean my script does an import that I'd like to mock, for example, import requests

Cheers!

@kvas-it
Copy link
Owner

kvas-it commented Nov 12, 2019

Hi @consal!

You can mock things out in the code that runs under script_runner using the normal approach (see monkeypatch fixture and pytest-mock plugin), however, this will only work in inprocess mode, when the console script is run in the same process as the test (see README for more info). Inprocess mode has some limitations (e.g. #24) but if your tests work in it, then mocking will just work as normal.

In subprocess mode mocking won't work because there the script under test runs in a separate Python process that pytest-console-scripts has no control over other than launching it.

Cheers,
Vasily

@kvas-it kvas-it closed this as completed Jun 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants