pytest cant import modules and gives SyntaxError

Question:

I am using pytest to test my functions in a directory that looks like this:

├── my_dir
    ├── Sam_Functions
        ├── __init__.py
        ├── AD.py                 
        ├── Pr.py
    ├── Test_Functions
        ├── __init__.py
        ├── test_AD.py
        ├── test_Pr.py  

AD.py and Pr.py work fine with no issues. However, in pytest I face these errors:

  • AttributeError: ‘module’ object has no attribute ‘choices’
  • AttributeError: ‘module’ object has no attribute ‘Seaborn’
  • SyntaxError: invalid syntax for *_ when I want to ignore last few outputs of AD.py

Any idea how I can resolve the issue?

Asked By: baharak Al

||

Answers:

try importing the other path:

import sys
sys.path.append("/my_dir/Test Functions")

or you can do it from the shell with:

setenv PATH $PATH:"my_dir/Test Functions"
Answered By: RAllenAZ

You missed to add path address into ur testing case.
You can add one more file and add path of dir and then call both test case into same. So thet u need not to add file again and again.
For debugging u can use print command and run this python test casees with specific options.

Secondly ut creating lib why r u not testing completely out of mydir folder.

Answered By: Chetan Ghangrekar