0

Why the next code works

python test.py
#Import libraries modules

import pandas as pd
import numpy as np
from clases.read_file import ReadFile
user_input='/home/folder1/Application/clases/file.txt'

#Test1
#Test data loaded from VCF file
data=Read File(user_input)
data_loaded data.load_data()

print(data_loaded.shape)

# Output (64, 10)

However, the next one doesn't work

pytest test.py
#Import libraries modules

import pandas as pd
import numpy as np
from clases.read_file import ReadFile

user_input='/home/folder1/Application/clases/file.txt'

#Test1
#Test data loaded from VCF file
data=Read File(user_input)
data_loaded data.load_data()

def test_1 ():
    assert data_loaded.shape == '(64, 10)'

Output:

E   ModuleNotFoundError: No module named 'clases'

It is the same file before and after changing the lines that differ. So they are in the same directory.

Why clases is recognized when called by python but it is not when using pytest

Directory structure

run.py
__init__.py
test.py
clases
     |- read_file.py
     |- __init__.py
     |
other_files

I am running this in an HPC Linux based

Monkiky
  • 173
  • 5
  • Without knowing more about where you are running your code and the underlying directory structure, it's hard to say exactly why the error is happening. But I'm pretty sure it's because of that. – Mad Physicist May 02 '22 at 19:00
  • I have added what you requested. Let me know if this is sufficient info or I should add something else – Monkiky May 02 '22 at 19:26
  • ok. python -m pytest test.py worlked. – Monkiky May 02 '22 at 19:38

0 Answers0