从子目录导入带有Nose的测试文件

2024-04-16 05:10:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道如何做鼻子采集测试文件。它能够自动递归地获取测试单元文件,但不能获取其中的.csv文件。下面是我的目录布局。你知道吗

工作

Test_Units
    |___nose.py
    |___test.csv
    |
    |___Test_Unit_1
            |_______Test_unit.py

非工作

Test_Units
    |___nose.py
    |
    |___Test_Unit_1
            |_______Test_unit.py
            |_______test.csv

好像nose需要这个文件在它的本地路径中。你知道吗

这里是如何鼻子.py已配置

import nose
result = nose.run()

测试单元如下所示:

from unittest import TestCase
from Quandl_RS_Lib import Quandl_Standard

Quandl_Standard = Quandl_Standard()


class TestQuandl_Standard(TestCase):

  def test_Top_Max(self):
      #Function stuff

Tags: 文件csvfrompytestimportunitnose
1条回答
网友
1楼 · 发布于 2024-04-16 05:10:17

我没能找到一个方法来纠正这个鼻子,但我找到了一个方法来解决这个问题。我继续告诉每个测试函数在测试开始前更改到正确的目录,这样它就能够找到正确的文件(下面的示例)。你知道吗

from unittest import TestCase
from Quandl_RS_Lib import Quandl_Standard
import os

Quandl_Standard = Quandl_Standard()


class TestQuandl_Standard(TestCase):

  def test_Top_Max(self):
      os.chdir("/path/to/yourfiles")
      #Function stuff

相关问题 更多 >