Git Product home page Git Product logo

Comments (4)

weiss-d avatar weiss-d commented on July 30, 2024 1

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.

kvas-it avatar kvas-it commented on July 30, 2024

I see two things here:

  1. test_import_my_script.py doesn't mock anything.
  2. 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.

weiss-d avatar weiss-d commented on July 30, 2024

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.

kvas-it avatar kvas-it commented on July 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.