DEV Community

Discussion on: Python TDD with Pytest -- Getting Started

Collapse
 
aderchox profile image
aderchox • Edited

I receive an error which begins like this(I've called my python file "main.py" instead of "hello.py"):

ERRORS =================================================================
_______________________________________________________ ERROR collecting main.py ________________________________________________________
env\lib\site-packages_pytest\python.py:493: in _importtestmodule
...

Can you help me with that? By the way this is a great tutorial Kinyanjui, can't thank you enough.
(P.S: Also just since it might matter, I'm on Windows and I activated the env using ".\env\Scripts\activate.bat" instead of the one you did in your terminal. I tested pytest --version and it's installed successfully.)

P.S #2: Sorry, I fixed it. I had a typo. But the error was scary and unreadable! Thanks anyways I enjoyed it very much when the test passed! :) I didn't delete the error so if someone else bumps into the same error can see my comment.

P.S #3: How about writing the test functions in a separate file? How should we run them? Should we use globs in that case? e.g: pytest test_*.py?

Collapse
 
wangonya profile image
Kelvin Wangonya

Hey @aderchox . If the test is in a different file, still just running pytest while in the project directory should discover the test files, as long as they're named in the format test_*.py.
You can read more about test discovery here.