首页 > 解决方案 > 与 python3.6 相比,使用 python3.7 的 pytest 运行时间几乎长 10 倍

问题描述

我正在一个名为 pdf2textbox 的模块上运行 pytests,为此我使用了 tox。python 3.5、3.6 和 3.7 的设置是相同的:

# tox.ini  
...   
[testenv]
    basepyton =  
        py35: python3.5  
        py36: python3.6  
        py37: python3.7  

    deps =
        check-manifest  
        pytest  
        requests  
        pdfminer2  
        pytest-cov  

    commands =
        check-manifest  
        python --version  
        py.test --cov=pdf2textbox tests

当我运行 tox 时,python3.5 和 python3.6 的时间大约是 58 或 59 秒。但是,python3.7 大约需要 8 分钟:

py36 inst-nodeps: .../.virtualenvs/pdf2textbox/.tox/dist/pdf2textbox-0.2.6.zip  
py36 installed: atomicwrites==1.1.5,attrs==18.1.0,certifi==2018.4.16,chardet==3.0.4,check-manifest==0.37,coverage==4.5.1,idna==2.7,more-itertools==4.2.0, pdf2textbox==0.2.6, pdfminer2==20151206,pluggy==0.6.0,py==1.5.4,pytest==3.6.3,pytest-cov==2.5.1, requests==2.19.1, six==1.11.0,urllib3==1.23  
py36 runtests: PYTHONHASHSEED='1111111111'  
py36 runtests: commands[0] | check-manifest  
some files listed as being under source control are missing:  
.tox/dist/pdf2textbox-0.2.4.zip  
lists of files in version control and sdist match  

py36 runtests: commands[1] | python --version  
Python 3.6.3

py36 runtests: commands[2] | py.test --cov=pdf2textbox tests  
============================ test session starts =============================
platform linux -- Python 3.6.3, pytest-3.6.3, py-1.5.4, pluggy-0.6.0  
rootdir: .../.virtualenvs/pdf2textbox, inifile:  
plugins: cov-2.5.1
collected 15 items                                                                    

tests/test_cli_slice_option.py ...         [ 20%]  
tests/test_convert_pdf.py ........         [ 60%]  
tests/test_get_pdf.py ............         [ 86%]  
tests/test_types.py ..............         [100%]

----------- coverage: platform linux, python 3.6.3-final-0 -----------  
Name                                       Stmts     Miss       Cover  
pdf2textbox/__init__.py                        1        0        100%  
pdf2textbox/pdf2textbox.py                   507      201         60%

TOTAL                                        508      201         60%

**================== 15 passed in 58.93 seconds ==============================**
py37 inst-nodeps: .../.virtualenvs/pdf2textbox/.tox/dist/pdf2textbox-0.2.6.zip  
py37 installed: atomicwrites==1.1.5,attrs==18.1.0,certifi==2018.4.16,chardet==3.0.4,check-manifest==0.37,coverage==4.5.1,idna==2.7,more-itertools==4.2.0,pdf2textbox==0.2.6,pdfminer2==20151206,pluggy==0.6.0,py==1.5.4,pytest==3.6.3,pytest-cov==2.5.1,requests==2.19.1,six==1.11.0,urllib3==1.23   
py37 runtests: PYTHONHASHSEED='2222222222'   
py37 runtests: commands[0] | check-manifest   
some files listed as being under source control are missing:   
.tox/dist/pdf2textbox-0.2.4.zip   
lists of files in version control and sdist match   

py37 runtests: commands[1] | python --version   
Python 3.7.0b3   

py37 runtests: commands[2] | py.test --cov=pdf2textbox tests   
========================== test session starts =================================
platform linux -- Python 3.7.0b3, pytest-3.6.3, py-1.5.4, pluggy-0.6.0   
rootdir: .../.virtualenvs/pdf2textbox, inifile:   
plugins: cov-2.5.1 collected 15 items                                                                    

tests/test_cli_slice_option.py ...         [ 20%]  
tests/test_convert_pdf.py ........         [ 60%]  
tests/test_get_pdf.py ............         [ 86%]  
tests/test_types.py ..............         [100%]

----------- coverage: platform linux, python 3.7.0-beta-3 -----------  
Name                                       Stmts     Miss       Cover  
pdf2textbox/__init__.py                        1        0        100%  
pdf2textbox/pdf2textbox.py                   507      201         60%

TOTAL                                        508      201         60%


**=================== 15 passed in 461.68 seconds =============================**

_______________________________ summary _______________________________________
  py35: commands succeeded   
  py36: commands succeeded   
  py37: commands succeeded   
  congratulations :)

测试时间:
py35:1 分钟
py36:1 分钟
py37:8 分钟

有谁知道为什么会这样?

标签: python-3.xpytesttox

解决方案


推荐阅读