如何存储python鼻子测试的测试数据? [英] How can I store testing data for python nosetests?

查看:81
本文介绍了如何存储python鼻子测试的测试数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为python MFCC 功能提取程序编写一些测试,以便与鼻子测试.除了进行一些较低级别的测试外,我还希望能够在单元测试中存储一些标准的输入文件和期望的输出文件.

I want to write some tests for a python MFCC feature extractor for running with nosetest. As well as some lower-level tests, I would also like to be able to store some standard input and expected-output files with the unit tests.

目前,我们正在对服务器上文件的路径进行硬编码,但我希望测试文件(输入文件和预期输出文件)位于代码存储库中的某个位置,以便可以将其保存在源代码控制下测试代码旁边.

At the moment we are hard-coding the paths to the files on our servers, but I would prefer the testing files (both input and expected-output) to be somewhere in the code repository so they can be kept under source control alongside the testing code.

我遇到的问题是我不确定放置测试文件的最佳位置在哪里,以及在鼻子测试调用每个测试函数时如何知道该路径是什么.目前,我正在考虑将测试数据存储在与测试相同的文件夹中,并使用__file__确定该在哪里(行得通吗?),但是我愿意接受其他建议.

The problem I am having is that I'm not sure where the best place to put the testing files would be, and how to know what that path is when nosetest calls each testing function. At the moment I am thinking of storing the testing data in the same folder as the tests and using __file__ to work out where that is (would that work?), but I am open to other suggestions.

推荐答案

我认为使用__file__找出测试的位置并在其中存储数据是一个好主意.对于编写的某些测试,我也是如此.

I think that using __file__ to figure out where the test is located and storing data alongside the it is a good idea. I'm doing the same for some tests that I write.

此:

os.path.dirname(os.path.abspath(__file__))

可能是您将获得的最好成绩,这还不错. :-)

is probably the best you are going to get, and that's not bad. :-)

这篇关于如何存储python鼻子测试的测试数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆