简体   繁体   English

将文件路径作为命令行参数输入 Pandas DF for PyTest

[英]Feed file path into Pandas DF for PyTest as command line parameter

so I am trying to find a way to parameterize tests a bit better for data validation.所以我试图找到一种方法来更好地参数化测试以进行数据验证。 I have basic tests I've created in PyTest that involve me reading a .csv file and loading it into a Pandas DF.我在 PyTest 中创建了一些基本测试,其中包括读取 .csv 文件并将其加载到 Pandas DF 中。 From there I'm doing simple checks like checking for duplicates, verifying data types and whatnot.从那里我正在做简单的检查,比如检查重复项、验证数据类型等等。 All of that works just fine.所有这些都很好。

However I want to be able to share the script with colleagues and allow for them to simply execute from the command line by feeding the file name into the test.但是,我希望能够与同事共享脚本,并允许他们通过将文件名输入测试来简单地从命令行执行。 I know that PyTest allows for parameterization but everything I've found thus far is for simple text and number inputs, haven't seen anything helpful for file inputs.我知道 PyTest 允许参数化,但到目前为止我发现的一切都是简单的文本和数字输入,没有看到任何对文件输入有帮助的东西。

Anyone had experience with this?有人有这方面的经验吗?

Maybe I'm not understanding what you're trying to do, but if you're trying to check that some tabular data is properly sanitized, that's not what pytest is for.也许我不明白您要做什么,但是如果您要检查某些表格数据是否已正确清理,那不是 pytest 的用途。 Pytest is for writing unit tests, and in that context it doesn't really make sense to share scripts with colleagues who would provide their own input files. Pytest 用于编写单元测试,在这种情况下,与提供自己的输入文件的同事共享脚本实际上没有意义。

I think what you want is a data validation library, eg pandera .我认为您想要的是一个数据验证库,例如pandera This would allow you to handle any command-line arguments yourself, and would also probably simplify the actual data validation steps.这将允许您自己处理任何命令行参数,并且还可能简化实际的数据验证步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM