I'm trying to execute 2 very basic unit tests, following the guide @ https://code.visualstudio.com/docs/python/testing. However, when attempting to run the unit tests, I receive the error:
Error: TypeError: Cannot read property '$' of undefined
I'm on Windows 10, Python 3.7.4, using latest version of VSCode.
On first attempting to run the tests (using the latest version of Pytest), I got the error "Error: TypeError: Cannot read property '$' of undefined". This led me to: https://github.com/microsoft/vscode-python/issues/6990
I then attempted to use the pip command outlined to downgrade my Pytest to the previous version (5.0.1). However, the 'pip' command was not recognized, so I figured it was something I had to enable in VSCode before using. Further googling led me to learn that it should be included by default when installing any version of Python > 3.0. I then thought it might need an extension, so I added the pip-packages extension to VSCode. Restarted & tried again - same error when atepmting to downgrade Pytest.
Further googling led me to: How to use pip with Visual Studio Code which pointed to instructions for adjusting system variables @ How to add to the PYTHONPATH in Windows, so it finds my modules/packages?.
I then attempted to adjust those variables, but it seemed to just cause further issues, so I undid those changes. Then, I asked a friend who said it should not be so complicated and advised that I first setup a virtual environment.
I went down the Venv path and after having a bunch of issues setting that up, I was successful and was able to set my Venv as the interpreter as well as install Pytest on the Venv as well.
I attempted to execute the tests again, now in the Venv and received the same error as before. This led me back to: https://github.com/microsoft/vscode-python/issues/6990
I was able to successfully downgrade my Pytest in the Venv to 5.0.1, as suggested in the github thread, then restarted VScode and executed the test again. Same error.
I was unable to find any further info - downgrading Pytest seems to have worked for everyone else.
The code that I am trying to test is:
inc_dec.py:
def increment(x):
return x + 1
def decrement(x):
return x - 1
The test cases I am trying to execute are:
pytest_test.py:
import inc_dec # The code to test
def test_increment():
assert inc_dec.increment(3) == 4
def test_decrement():
assert inc_dec.decrement(3) == 4
I would expect the first unit test to pass, and the second unit test to fail. Instead, I receive the error: Error: TypeError: Cannot read property '$' of undefined
Alright - so after many headaches, my issue was fairly simple, though not obvious to me due to lack of experience.
Basically - I had:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With