Pytest卡住了``收集...''

时间:2019-09-02 23:19:01

标签: python pandas testing pytest

我有一个文件 new_script_piped.py ,其中包含我要测试的功能:

def columns_preparation(df):

    df.COLUMN_1.replace({'-999':'don't consider'}, inplace=True)
    ...more lines

    return df

和测试文件 test_new_script_piped.py

import pandas as pd
import new_script_piped as x

def test_columns_preparation(df):

    test_df = pd.read_excel('test_column_preparation.xlsx')
    result_df = pd.read_excel('test_column_preparation_result.xlsx')

    assert x.columns_preparation(test_df) == result_df

所有文件都在同一目录中。我在命令行上尝试过:

python3 -m pytest new_script_piped.py
pytest new_script_piped.py
python -m pytest new_script_piped.py

他们都被吸引到:

platform darwin -- Python 3.7.3, pytest-4.5.0, py-1.8.0, pluggy-0.11.0
rootdir: /Users/31275553/Documents/
collecting ... 

其他解决方案建议检查拼写错误,并确保所有文件都在同一文件夹中,但是我已经遵守了。 我的python解释器是:/.conda/envs/untitled/bin/python

3 个答案:

答案 0 :(得分:1)

通过缩小搜索目录的范围,我可以通过config而不是通过提供测试的路径来减少“收集...”的延迟,从而缩小了搜索目录的范围,从而达到了与finomayato的答案相同的效果。一个论点。

根据文档中的示例,假设您要确保pytest不会深入到git,build或前端依赖目录中以寻找测试:

# content of pytest.ini
[pytest]
norecursedirs = .git build node_modules

https://docs.pytest.org/en/latest/example/pythoncollection.html#changing-directory-recursion

答案 1 :(得分:0)

您的考试可能要花很长时间

pytest -s path_to_script.py  

为了查看stdout是否有任何打印进度

答案 2 :(得分:-1)

您有两个选择:

  • 使用这两个文件创建一个单独的模块,然后从该目录运行pytest

  • 指定文件/文件夹以通过执行pytest test_new_script_piped.py

  • 查找测试

由于pytest递归地查找测试,因此该问题可能是由在目录中执行包含大量文件的pytest命令引起的(根据您提供的rootdir: /Users/31275553/Documents/的判断,这可能是正确的)在摘要中)。

如果所有选项都不起作用-最好知道/Users/31275553/Documents/目录中的内容