简体   繁体   中英

Missing required dependencies when testing with py.test

I have a python file which contains classes and functions and a

if __name__ == "__main__":
    ...

construct. I want to test a class which is defined in this file with py.test. For my first "hello world"-test, my test-file only imports the file to be tested.

Running py.test in PyCharm results however in

raceback (most recent call last):
  File "[...]/unittest/datageneration_test.py", line 1, in <module>
    from main.datageneration import *
  File "[...]/main/datageneration.py", line 1, in <module>
    import pandas as pd
  File "[...]/lib/python3.6/site-packages/pandas/__init__.py", line 19, in <module>
    "Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']

My file to be tested has the import statements

import pandas as pd
import numpy as np
from scipy.special import expit
import sys
import os
import scipy.io.wavfile as wav
import json
import uuid

My conda environment.yml is

channels:
- conda-forge
- defaults
dependencies:
- pandas=0.20.3
- numpy=1.13.1
- ggplot=0.11.5
- python=3.6.2
- pytest=3.2.1

What is the issue here?

I am not quite sure what helped, but I reinstalled/updated numpy and pandas with conda install ... . I was still left with an error about having wrong file names. After trying out a lot of stuff I found out that - even though I was using pytest, not the library unittest - I could not name the folder in which all my test files are "unittest". Renaming it to "unittests" solved that. Now everything works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM