Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
已跳过Python预提交单元测试_Python_Git_Python Unittest_Githooks_Pre Commit.com - Fatal编程技术网

已跳过Python预提交单元测试

已跳过Python预提交单元测试,python,git,python-unittest,githooks,pre-commit.com,Python,Git,Python Unittest,Githooks,Pre Commit.com,我想使用它为我的git项目处理git钩子。但是,当我使用它时,git commit命令会一直跳过unittest执行: (smartexchange) trnbook:SmartExchange ale$ git commit -m "add pre-commit yaml config" autopep8.............................................(no files to check)Skipped unittest................

我想使用它为我的git项目处理git钩子。但是,当我使用它时,
git commit
命令会一直跳过
unittest
执行:

(smartexchange) trnbook:SmartExchange ale$ git commit -m "add pre-commit yaml config"
autopep8.............................................(no files to check)Skipped
unittest.............................................(no files to check)Skipped
[hook_precommit da26d1e] add pre-commit yaml config
1 file changed, 14 insertions(+)
create mode 100644 .pre-commit-config.yaml
(smartexchange) trnbook:SmartExchange ale$ pre-commit install && python .git/hooks/pre-commit
pre-commit installed at .git/hooks/pre-commit
autopep8.............................................(no files to check)Skipped
unittest.............................................(no files to check)Skipped
预提交钩子手动执行时的结果相同:

(smartexchange) trnbook:SmartExchange ale$ git commit -m "add pre-commit yaml config"
autopep8.............................................(no files to check)Skipped
unittest.............................................(no files to check)Skipped
[hook_precommit da26d1e] add pre-commit yaml config
1 file changed, 14 insertions(+)
create mode 100644 .pre-commit-config.yaml
(smartexchange) trnbook:SmartExchange ale$ pre-commit install && python .git/hooks/pre-commit
pre-commit installed at .git/hooks/pre-commit
autopep8.............................................(no files to check)Skipped
unittest.............................................(no files to check)Skipped
我错过了什么?手动执行
python-m unittest discover
没有问题,它执行4个unittest:

(smartexchange) trnbook:SmartExchange ale$ python -m unittest discover -s smartexchange/
....
----------------------------------------------------------------------
Ran 4 tests in 0.001s

OK
我已经阅读了预提交用户文档和以下答案:

这是我的
.pre-commit config.yaml
文件

repos:
-   repo: https://github.com/pre-commit/mirrors-autopep8
    rev: ''  # Use the sha / tag you want to point at
    hooks:
    -   id: autopep8
-   repo: local
    hooks:
    -   id: unittest
        name: unittest
        entry: python -m unittest discover 
        language: python
        'types': [python]
        additional_dependencies: []
        pass_filenames: false
我担任环境经理。这里是我的
conda列表
输出:

(smartexchange) trnbook:SmartExchange ale$ conda list
# packages in environment at /Users/ale/bin/miniconda3/envs/smartexchange:
#
# Name                    Version                   Build  Channel
aspy.yaml                 1.3.0                      py_0    conda-forge
ca-certificates           2019.11.27                    0  
cached-property           1.5.1                      py_1  
certifi                   2019.11.28               py37_0  
cfgv                      2.0.1                      py_0    conda-forge
editdistance              0.5.3            py37h0a44026_0    conda-forge
identify                  1.4.9                      py_0    conda-forge
importlib_metadata        1.3.0                    py37_0  
libcxx                    4.0.1                hcfea43d_1  
libcxxabi                 4.0.1                hcfea43d_1  
libedit                   3.1.20181209         hb402a30_0  
libffi                    3.2.1                h475c297_4  
more-itertools            8.0.2                      py_0  
ncurses                   6.1                  h0a44026_1  
nodeenv                   1.3.3                      py_0    conda-forge
openssl                   1.1.1d               h1de35cc_3  
pip                       19.3.1                   py37_0  
pre-commit                1.21.0                   py37_0    conda-forge
python                    3.7.5                h359304d_0  
pyyaml                    5.2              py37h1de35cc_0  
readline                  7.0                  h1de35cc_5  
setuptools                42.0.2                   py37_0  
six                       1.13.0                   py37_0  
sqlite                    3.30.1               ha441bb4_0  
tk                        8.6.8                ha441bb4_0  
toml                      0.10.0           py37h28b3542_0  
virtualenv                16.7.5                     py_0  
wheel                     0.33.6                   py37_0  
xz                        5.2.4                h1de35cc_4  
yaml                      0.1.7                hc338f04_2  
zipp                      0.6.0                      py_0  
zlib                      1.2.11               h1de35cc_3  
我使用的操作系统是MacOS Catalina,版本10.15.2


编辑:

环境是好的;不过,为了便于将来参考,最好报告我用来运行
unittest
命令(此处)的修改配置,选项为
--start directory=path/to/python\u module\u folder

    -   id: unittest
        name: unittest
        entry: python -m unittest discover
        language: python
        types: [python]
        args: [--start-directory=path/to/python_module_folder, --pattern=test_*.py]
        pass_filenames: false
        verbose: true

正如所报告的,其他参数应该在中。

预提交
将仅在特定提交中运行钩子

此配置:

    -   id: unittest
        name: unittest
        entry: python -m unittest discover 
        language: python
        'types': [python]
        additional_dependencies: []
        pass_filenames: false
仅当匹配了
types:[python]
文件时才会运行(对于
git commit
,这意味着需要更改python文件才能执行)

如果希望它始终运行,可以使用
始终\u run:true
(不过,您可能可以节省一些时间)

如果您有任何python文件(将由
类型:[python]
匹配),也可以使用
预提交运行--all files


一些额外的提示

  • 您不需要引用
    'types'
    (只需使用
    types
    ,因为yaml支持裸字)
  • 其他依赖项:[]
    是默认值,您可以删除此行


免责声明:我是
pre-commit

pre-commit
的作者,它只会在您的特定commit中运行钩子

此配置:

    -   id: unittest
        name: unittest
        entry: python -m unittest discover 
        language: python
        'types': [python]
        additional_dependencies: []
        pass_filenames: false
仅当匹配了
types:[python]
文件时才会运行(对于
git commit
,这意味着需要更改python文件才能执行)

如果希望它始终运行,可以使用
始终\u run:true
(不过,您可能可以节省一些时间)

如果您有任何python文件(将由
类型:[python]
匹配),也可以使用
预提交运行--all files


一些额外的提示

  • 您不需要引用
    'types'
    (只需使用
    types
    ,因为yaml支持裸字)
  • 其他依赖项:[]
    是默认值,您可以删除此行

免责声明:我是
pre-commit