运行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
最满意答案
您没有使用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.
相关问答
更多-
EF 4:从集合中删除子对象不会将其删除 - 为什么?(EF 4: Removing child object from collection does not delete it - why?)[2022-01-31]
您没有使用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 ...
-
麻烦EF“保存”方法,修改了子实体的集合(Trouble with EF “Save” method, modified collection of child entities)[2023-12-06]
也许我错过了一些东西,但对我来说这段代码看起来过于繁琐。 如果我在这里错误的轨道并且误解了你,请耐心等待我。 关于应删除的对象,我建议您将这些对象存储在仅包含已删除项目的单独集合中。 您可以从ObjectContext删除它们。 我会调用myObjectContext.SaveChanges() ,而不是调用ApplyCurrentValues。 在这种情况下,ApplyCurrentValues的缺点是它不会处理与您正在保存的实体有关系的任何其他实体。 MSDN文档: 将提供的对象中的标量值复制到Obje ... -
使用EF6删除子对象(Deleting child objects with EF6)[2023-06-16]
您已经知道改变了什么,这意味着您必须重新从数据库中选择原始人。 然后你可以这样做: var removedRecords = person.SicknessRecords.Except(model.SicknessRecords); for (var record in removedRecords) { person.SicknessRecords.Remove(record); } 您应该始终使用发布的数据修改原始记录,而不是直接保存发布的数据。 You have know what chan ... -
EF删除子对象(EF Delete Child Object)[2023-08-30]
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 ...
-
EF 5.0删除不起作用(EF 5.0 delete not working)[2022-05-29]
看看这个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 ... -
EF:在LINQ查询中使用Contains时的SQL输出是什么?(EF: What is the SQL output when using Contains in LINQ query?)[2022-05-29]
我已经为你看了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 ...