[英]RSpec collection without running tests
Is there a way to trigger RSpec test case collection, but not run the tests?有没有办法触发 RSpec 测试用例收集,但不运行测试?
In Python's pytest, the equivalent is appending a --collect-only
switch.在 Python 的 pytest 中,相当于附加了一个
--collect-only
开关。
My use case : I would like to run a hook that validates some metadata about our test cases, such as enforcing a mandatory tagging pattern, and I'd like to include this validation check as a PR check.我的用例:我想运行一个钩子来验证有关我们的测试用例的一些元数据,例如强制执行强制标记模式,我想将此验证检查作为 PR 检查包含在内。 The issue is, I don't really want the test suite to run, but I would only like to validate test case metadata.
问题是,我真的不希望测试套件运行,但我只想验证测试用例元数据。
Any help would be appreciated and thank you in advance!任何帮助将不胜感激,并提前感谢您!
There seems to be no built-in way to do collection only.似乎没有内置的方法只能进行收集。 Instead, I had to add the following in my
spec_helper
.相反,我必须在我的
spec_helper
添加以下spec_helper
。 Basically, skip the test if you pass in an environment variable CONTEXT=validate
into your test run.基本上,如果您将环境变量
CONTEXT=validate
传递到您的测试运行中,则跳过测试。 Not really a great way to do this but it seems RSpec provides no built-in alternative:这不是一个很好的方法,但似乎 RSpec 没有提供内置的替代方案:
config.around(:each) do |example|
# validate test case metadata. Ensure proper folder structure and team tagging
# No need to run tests during validation, so they are skipped and left in 'pending' state
if CONTEXT == 'validate'
puts '[INFO] Skipping spec run and validating spec'
example.skip
validate_spec(example)
else
example.run
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.