0

I'm trying to run tests from the terminal and then push my code to a branch which will trigger a jenkins build and it triggers the test cases there as well, but I keep running into this error: If I run it locally using pycharm it works fine but when I use the terminal it tells me that it can't find the module.

My file tree looks like this:

uitests contains:

__init__.py
__pycache__
data
tests (contains all my test classes)
utilfile (contains the configm drivers, random data and init files)
requirements.txt (contains the dependencies as well as the versions)
uicases (contains the page object modal pages)

Then I cd into tests and this is where my cases are but the uicases is where my Page object mode pages are located. I utilize these pages in my tests to write my test cases which import

So when I cd into the tests folder and try to run a test case, I encounter the following problem:

    ImportError while loading conftest '/Users/user/Desktop/Projects/reponame/uitests/tests/conftest.py'.
    conftest.py:10: in <module>
        from uitests.uicases.pom.login_page import LoginPage
    ../uicases/pom/login_page.py:13: in <module>
        from uitests.wgsnui.util.common import Common
    ../uicases/util/common.py:9: in <module>
        from utilfile.config import ConfigFile
    E   ModuleNotFoundError: No module named 'utilfile'

I feel like I'm doing something wrong, I don't want to just fix it locally i also want it so that when I fix it and push my code it is also able to run it on the jenkins server. Please guide me any way possible, I'm pretty lost and if you guys need more information, please let me know.

Ali Ahmad
  • 29
  • 4

1 Answers1

0

The issue is happening because the utilfile is not in the same directory as the file (conftest.py) where it is being imported. By default, Python imports work by searching the current directory for the modules being imported. You need to do something like this https://stackoverflow.com/a/50474562/5493999

Abdul Mateen
  • 1,418
  • 1
  • 14
  • 32