Very, very good explanation. You did a great job of explaning how mocks work, and showing their value in a very practical way. Thanks!
Thank you so much 👍 hopefully disconnecting my network connection really showed their usefulness!
This can be pretty confusing for those of us starting out with mock and patch. This was really clear. Thanks. (Thumbs up, subscribed).
Thank you. I tried to keep it very focussed. Thanks for subscribing, really appreciate it 👍
Good to learn from "Jean Claude Van Damme" :) On serious note , please post more pytest, you method of teaching is v good.
Hi when running the tests I get error "modulenotfounderror no module named app" . I know there is something wrong with the relative imports? but I followed your structure exactly
try : python3.10 -m pytest
see also : github.com/RGGH/mok
clone it and see it it works?
Thank You so much
Thank you! + Let me know if you would like a future video on a specific topic 👍
When I enter this line: "from app.fetch_www import parse".
It shows the error: Import "app.fetch_www"cannot be resolved. Pylance (reportMissingImports).
Do you know how to fix?
Hi, yes, so that was my particular set up, so to do the same you will need a directory called "app" and then have "fetch_www.py" inside it. If you're using VS Ccode, when you start the imports at the top of your python file, the autocomplete should offer you the completion of the correct filepath.
If your directory structure is different try . or .. before the file you want to import (and leave off the .py ) when you write the import at the top of the file.
ps. from app.fetch_www import parse ~ Those are MY file names, not standard library, so you'll need to replicate what I coded if you haven't done so.
Cheers
Dr Pi.
How do we test a function that needs arguments with this method ?
I made a gist : gist.github.com/RGGH/557b9e9ee710242b48f9503f0141e058
Hope this answers?!
since app is one directory up from tests/test_bcd.py, how can you import it such as from app.fetch_www import parse?
This would need to go one directory up first?
.
├── app
│ └── fetch_www.py
└── tests
└── test_bcd.py
have you got the structure as above? (have you got tree installed, it's great for this kind of stuff)
Yes just like this.. even added __init__.py files in app/ and tests/
Been banging my head on this one. I'm working on a mac in vs code
I typed it all back in as I'd not kept the project, I tested it and it works ok : github.com/RGGH/mok
One tip : specify your python version if you are doing it from command line : eg :
$python3.10 -m pytest
@@python360 I saw this in the repo
Add the project root directory to the PYTHONPATH
# Replace '/home/rag/Documents/python/mok
I didn't do this, that could be it no?
@@mytrustysteed8476 Yes, PATH can be a problem - if you use "python3.10 -m pytest" or whatever version of python you use then this should work.
You can run "which python" and "which pytest" from terminal to check the paths..
See this : g.co/gemini/share/b76c08a4f516
PATH is a pain, but as it works on my set up then, check PATH, make sure you have __init__.py and also you can drag the file icon from VSCode file explorer, and hold down shift and drop it in between quotes when trying to get the right path into your python code.
theme name
Anime girl next time pls
This is the easiest and clearest explanation that i've seen so far!! It helped me immensely, thank you so much!!!
Thank you so much for your comment, this is really good to hear!!