首页 \ 问答 \ 运行pytest来断言整个脚本的输出(Running pytest to assert output of an entire script)

运行pytest来断言整个脚本的输出(Running pytest to assert output of an entire script)

在使用pytest分别测试脚本函数之后,我想通过提供命令行参数并让它完整运行来测试几个用例。 然后我想将输出与我预期的输出进行比较。 我可以通过pytest做到这一点吗?

如果我不能通过命令行输入对整个脚本执行此操作,则必须模拟argparse。 你能指出哪种方法最好吗? 谢谢!

Python 2.7.12, pytest-3.0.2, py-1.4.31, pluggy-0.3.1

After testing a script's functions separately with pytest, I'd like to test several use-cases by supplying command-line arguments and letting it run in its entirety. Then I'd like to compare the output with my expected output. Can I do this via pytest?

If I can't do this to an entire script via command-line input, I'd have to mock argparse. Can you point me to which is the best approach? Thanks!

Python 2.7.12, pytest-3.0.2, py-1.4.31, pluggy-0.3.1

原文:https://stackoverflow.com/questions/39451811
更新时间:2022-03-19 13:03

最满意答案

您没有使用remove语句删除对象。 相反,您正试图更改记录并将其设置为孤立(通过将外键设置为空)。 该数据库在该列上有一个非空约束,并阻止您这样做。


You aren't deleting the object with the remove statement. Instead you are attempting to alter a record and make it an orphan (by setting the foreign key to null). The database has a non-null constraint on that column and prevents you from doing so.

相关问答

更多
  • 您没有使用remove语句删除对象。 相反,您正试图更改记录并将其设置为孤立(通过将外键设置为空)。 该数据库在该列上有一个非空约束,并阻止您这样做。 You aren't deleting the object with the remove statement. Instead you are attempting to alter a record and make it an orphan (by setting the foreign key to null). The database has ...
  • 更换 mockSet .Setup(m => m.Remove(It.IsAny())) .Callback((entity) => students.Remove(entity)); 同 dbContext .Setup(m => m.Students.Remove(It.IsAny())) .Callback((entity) => students.Remove(entity)); 大多数设置是 ...
  • EF并不是SQL的直接替代品。 它旨在使单个记录的使用变得容易。 因此,它将为每条记录发出单独的命令。 EF不是批量操作的正确工具。 只要您将所有子项加载到内存中,EF将自动将ParentId属性设置为null。 但是,此方法仍将发出单独的更新。 有关详细信息,请参阅EntityFramewok:如何配置Cascade-Delete以使外键无效 EF is not meant as a direct replacement for SQL. It is designed to make it easy to ...
  • 也许我错过了一些东西,但对我来说这段代码看起来过于繁琐。 如果我在这里错误的轨道并且误解了你,请耐心等待我。 关于应删除的对象,我建议您将这些对象存储在仅包含已删除项目的单独集合中。 您可以从ObjectContext删除它们。 我会调用myObjectContext.SaveChanges() ,而不是调用ApplyCurrentValues。 在这种情况下,ApplyCurrentValues的缺点是它不会处理与您正在保存的实体有关系的任何其他实体。 MSDN文档: 将提供的对象中的标量值复制到Obje ...
  • 您已经知道改变了什么,这意味着您必须重新从数据库中选择原始人。 然后你可以这样做: var removedRecords = person.SicknessRecords.Except(model.SicknessRecords); for (var record in removedRecords) { person.SicknessRecords.Remove(record); } 您应该始终使用发布的数据修改原始记录,而不是直接保存发布的数据。 You have know what chan ...
  • EF表示该对象被修改而不是删除,因为从父集合中删除它正在修改它,而不是删除它。 要删除它,请在包含要删除的对象的对象集上使用DeleteObject()方法,例如: myObjectContext.StockTransferItems.DeleteObject(stockTransferItemToDelete); The EF says the object is modified rather than deleted because removing it from a parent collect ...
  • 我更改了模型,通过使用包含父键的复合键来确定父和子身份之间的关系来识别关系。 这意味着从子集合中删除实体会将其删除,而无需访问上下文。 查看此问题是否可以从收集中删除子项并解决SaveChanges上的问题? I changed the models to make the relationships between parent and child identities identifying relationships by using a composite key containing the pa ...
  • 看看这个SO问题 ,我认为接受的答案应该指向正确的方向。 你如何选择解决它取决于你,但我认为这说明了为什么EF的行为方式。 Looking at this SO Question, I think the accepted answer should point you in the right direction. How you choose to solve it is up to you, but I think this lays out why EF is behaving the way it ...
  • 我已经为你看了SQL分析器。 这就是实体框架中发生的事情(我认为这是wat NHibernate也会产品,但我不确定..): SELECT [Extent1].[Id] AS [Id], [Extent1].[AccountNo] AS [AccountNo], [Extent1].[Name] AS [Name], [Extent1].[Description] AS [Description], [Extent1].[IBAN] AS [IBAN], [Extent1].[IsActive] ...
  • Hi I tried with same structure in EF 6.1.3 version and it worked like charm .I added image of output and data present in db .The only thing that might stoped working if you disable loading in configuration . I hope it work for you please try my sample code ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)