[FIXED] Issue with testing Class methods in Pytest

Issue

I am trying to run a test in one folder (folder A) calling a class made in a different folder (folder B), but both folders (A and B) are located in the same directory. And when I run the test file, it is giving me import errors of the class created in the folder B.

Error in Gitbash:

[![][1]][1]

And you can see the directory flow

Path directory in VSCode:


Solution

It's because the testing folder is not in the PYTHONPATH.

You can add your workspace folder(testing) into the PYTHONPATH through add this in the settings.json:

  "terminal.integrated.env.windows": {
    "PYTHONPATH": "${workspaceFolder};"
  },

And then you can import accum.py from stuff package directly: from stuff import accum.



Answered By - Steven-MSFT
Answer Checked By - Timothy Miller (Python.Easybugfix Admin)

Related Posts

Post a Comment