【发布时间】:2019-03-21 05:59:14
【问题描述】:
我正在为 Keras 框架开发一个自定义层,并希望扩展他们现有的测试套件。
由于我正在处理 keras 源代码,所以我已经这样安装它:
pip install keras-preprocessingpip install keras-applicationsgit clone https://github.com/keras-team/kerascd kerasexport PYTHONPATH=$PWD:$PYTHONPATH
执行这些命令后,您将进入克隆的 keras 存储库,这是下面代码示例的工作目录。
首先,我想运行现有的测试并看看它们做了什么。 It looks like 它们可以简单地作为 python 文件运行:
if __name__ == '__main__':
pytest.main([__file__])
但是这个:
python tests/keras/layers/wrappers_test.py
产生以下输出,并且不运行任何测试
Using TensorFlow backend.
usage: wrappers_test.py [options] [file_or_dir] [file_or_dir] [...]
wrappers_test.py: error: unrecognized arguments: -n tests/keras/layers/wrappers_test.py
inifile: /home/lhk/programming/keras/pytest.ini
rootdir: /home/lhk/programming/keras
所以我尝试下一个显式调用 pytest:
pytest tests/keras/layers/wrappers_test.py
完全相同的响应(没有 tensorflow 日志):
usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: -n tests/keras/layers/wrappers_test.py
inifile: /home/lhk/programming/keras/pytest.ini
rootdir: /home/lhk/programming/keras
我正在使用 PyCharm,如果我从 pycharm 中运行测试(我承认首先尝试过),它只会产生上面的消息。
显然,我没有正确配置它。 Pytest 无法获取测试套件。为了找到参考配置,我查看了 Keras CI 设置。他们使用 Travis,配置是开源的:https://travis-ci.org/keras-team/keras/jobs/442252422/config
看起来我已经安装了所有依赖项。而实际的测试命令基本上是我已经尝试过的:
PYTHONPATH=$PWD:$PYTHONPATH py.test tests/ --ignore=tests/integration_tests --ignore=tests/test_documentation.py --ignore=tests/keras/legacy/layers_test.py --cov-config .coveragerc --cov=keras tests/
它产生与上面完全相同的输出。
我认为问题在于 pytest。但是他们自动化测试的安装部分只是显示pip install pytest pytest-pip8。我运行了这个,但果然,requirement already satisfied。
如何执行 keras pytest。 我正在运行 ubuntu 18.04.1、python 3.6.5 和 anaconda 64bit。
【问题讨论】:
-
您缺少用于测试的
pytest插件;看起来你没有安装所有的测试部门。检查keras' 设置脚本,他们定义了tests附加功能,所以发出pip install --editable .[tests]一个简单的方法(同样,你不需要在该命令之后调整PYTHONPATH),或者只是显式安装测试包:pip install pytest pytest-pep8 pytest-xdist pytest-cov pytest-timeout pandas requests. -
@hoefling,终于开始测试了。如果您将其发布为答案,我会接受它
标签: python keras anaconda travis-ci pytest