Comments (4)
No worries, it happens. BTW, if you have further problems with mocking in the scripts you might want to check out this issue #44 -- the discussion there and the linked stackoverflow thread clarify some issues related to mocking and scripts.
Funny enough, I had no problem with this one cause I got there straight from readme)
Now everything is working with mocks and imports. Big thanks for this tool!
from pytest-console-scripts.
I see two things here:
test_import_my_script.py
doesn't mock anything.- More importantly, the prints in
mock_check.my_script
are executed when it is imported, which is before any tests are executed or any fixtures are created. Even if there was mocking, it would not be in effect yet.
I think the behavior that you observe is exactly how it should be. The content of sys.argv
is also correct. It's the sys.argv
of the pytest
process (which imports mock_check.my_script
where that print is located via test_import_my_script.py
), so it contains the path to pytest
.
To summarize: mocking only applies while the mocking fixture is in effect, which is inside of test_mock_check
. For the rest of the time requests.get
is the original one and it can't get "fake.url".
Does this make sense?
from pytest-console-scripts.
Well, thanks for pointing out the import issue. I tried to simplify the example and renamed my_scrip.py. Originally it was main.py and contained some code not wrapped into if __name__ == "__main__"
. While I've been blaming the mocking, the problem was that I looked right trough this unwrapped code. 🤦♂️ Sorry for the bustle.
from pytest-console-scripts.
No worries, it happens. BTW, if you have further problems with mocking in the scripts you might want to check out this issue #44 -- the discussion there and the linked stackoverflow thread clarify some issues related to mocking and scripts.
from pytest-console-scripts.
Related Issues (20)
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcb in position 24: invalid continuation byte HOT 8
- Running scripts that have not been installed HOT 10
- Encoding issues under Windows HOT 12
- extremely slow execution of script tests HOT 3
- Can I mock a function in the called script? HOT 5
- Add option to suppress printing RunResult on init HOT 8
- Cross OS support? HOT 11
- Mocking script methods when testing with pytest-console-scripts HOT 3
- print_result='on_fail' HOT 9
- “python_requires” should be set with “>=3.6”, as pytest-console-scripts 1.2.2 is not compatible with all Python versions. HOT 1
- PyPI Wheels? HOT 3
- 1.3.1: missing install-time dependencies HOT 5
- Test fails when called alone, succeeds with whole test module HOT 8
- Testing scripts which trigger user input HOT 4
- script_runner fixture type-hint. HOT 2
- Parity with subprocess.run HOT 3
- thank you for writing pytest-console-scripts
- Decode error when using inprocess tests on windows 10 HOT 1
- `pytest-console-scripts` causes `pytest-xdist` tests to fail HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytest-console-scripts.