Skip all testthat tests when condition not met
<p>What is the proper way to skip all tests in the test directory of an R package when using testthat/devtools infrastructure?  For example, if there is no connection to a database and all the tests rely on that connection, do I need to write a <code>skip</code> in all the files individually or can I write a single <code>skip</code> somewhere?</p>
<p>I have a standard package setup that looks like</p>
<blockquote>
<p>mypackage/</p>
<ul>
<li>...  # other package stuff</li>
<li>tests/
<ul>
<li>testthat.R</li>
<li>testthat/
<ul>
<li>test-thing1.R</li>
<li>test-thing2.R</li>
</ul>
</li>
</ul>
</li>
</ul>
</blockquote>
<p>At first I thought I could put a test in the <code>testthat.R</code> file like</p>
<pre><code>## in testthat.R
library(testthat)
library(mypackage)

fail_test &lt;- function() FALSE
if (fail_test()) test_check(&quot;package&quot;)
</code></pre>
<p>but, that didn't work and it looks like calling <code>devtools::test()</code> just ignores that file.  I guess an alternative would be to store all the tests in another directory, but is there a better solution?</p>