简体   繁体   English

如何保护金字塔注册表免受测试更改?

[英]How to protect a pyramid registry from changes for tests?

I'm trying to write sensible pytest fixtures for testing large pyramid applications.我正在尝试编写合理的pytest固定装置来测试大型金字塔应用程序。

One of the things I'm trying is to do to speed up test execution is to create the pyramid wsgi app as a session fixture rather than a test fixture , as this creation is reasonably expensive and yet is needed by most tests.我正在尝试做的一件事是加快测试执行速度,即创建金字塔 wsgi 应用程序作为会话夹具而不是测试夹具,因为这种创建相当昂贵,但大多数测试都需要。

But if any test messes with the app registry in the mean time, the registry will remain polluted for the rest of the test run, and this kind of breakage is difficult to locate as it usually manifests as failures in some random tests in further down the same test run.但是如果在此期间任何测试与应用程序注册表混淆,注册表将在测试运行的其余部分保持污染,并且这种破坏很难定位,因为它通常在一些随机测试中表现为失败相同的测试运行。

So I'd like to be able to either rollback changes to a registry on a fixture teardown or clone a pyramid registry on a fixture set up.所以我希望能够在夹具拆卸时回滚对注册表的更改,或者在夹具设置上克隆金字塔注册表。

Bonus points if I can lock a registry to raise errors if anyone tries to change a locked down registry.如果有人试图更改锁定的注册表,我可以锁定注册表以引发错误,则奖励积分。

Question

How do I make sure to always come back to the same pyramid registry while avoiding creating a new wsgi app at every test run?我如何确保总是回到同一个金字塔注册表,同时避免在每次测试运行时创建新的 wsgi 应用程序?

The registry does not have a supported api for freezing itself.注册表没有用于冻结自身的受支持 api。 You could subclass it and override some methods to make it readonly-ish if you wanted but it's certainly a bit tedious.如果您愿意,您可以将其子类化并覆盖一些方法以使其成为只读的,但这肯定有点乏味。 Things like setattr, registerUtility, etc.诸如 setattr、registerUtility 之类的东西。

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

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