1. 학습
  2. /
  3. 강의
  4. /
  5. 使用 Python 的 ETL 和 ELT

Connected

연습 문제

使用 pytest 创建 fixture

在编写单元测试时,您有时需要在测试开始前做一些准备工作。如果把这些准备直接写在单元测试里,会让测试更难读,而且可能需要重复多次。好在 pytest 提供了 fixture,可以用来解决这些问题。

在本练习中,pandas 已经以 pd 导入,并且可以使用下面的 extract() 函数!

def extract(file_path):
    return pd.read_csv(file_path)

지침

100 XP
  • 导入 pytest 库。
  • 创建名为 raw_tax_data 的 pytest fixture。
  • 返回 raw_data DataFrame。