title: Bazel and py_test in sandbox - any way to define outputs?
body: <p>I'm running multiple <code>py_test()</code> configurations on number of projects. Since there's a plenty of them, the default sandboxing mechanism seems convenient - tests don't intrude one another, and run in parallel for free.</p>
  
  <p>This comes with a cost, though, as to my understanding sandboxing will cause bazel to run the tests in temporary directories. Combined with <code>py_test</code> rule not defining any <em>outs</em> parameter (<a href="https://docs.bazel.build/versions/master/be/python.html" rel="noreferrer">https://docs.bazel.build/versions/master/be/python.html</a>), this likely means no generated file will be preserved after the test.</p>
  
  <p>What I want to achieve, are two things: </p>
  
  <ol>
  <li>Preserve output of the test, split by test case (I think I can get it to work using <code>capsys</code> and explicitly writing to a file named similarly to the test name). The problem here is, the file will end up in a sandboxed directory, i.e.: 
  <code>/home/user/.cache/bazel/_bazel_user/12342134213421342134/sandbox/linux-sandbox/1/execroot/project_name/bazel-out/k8-fastbuild/bin/test_suite.runfiles/</code>
  and will be removed afterwards.</li>
  <li>I would like to get a run tests summary in an XML format. Bazel by itself generates an XML file in JUnit format, which would be fine, but unfortunately it does not work properly (<a href="https://github.com/bazelbuild/bazel/issues/3413" rel="noreferrer">https://github.com/bazelbuild/bazel/issues/3413</a>). The easiest solution would be to provide a parameter <code>--junitxml=path</code> (<a href="https://docs.pytest.org/en/latest/usage.html#creating-junitxml-format-files" rel="noreferrer">https://docs.pytest.org/en/latest/usage.html#creating-junitxml-format-files</a>) which works, but again - generates a file in the temporary, sandboxed directory.</li>
  </ol>
  
  <p>Other rules in bazel define <em>outs</em> as the files that they will generate, i.e. <a href="https://docs.bazel.build/versions/master/be/make-variables.html#predefined_genrule_variables" rel="noreferrer">https://docs.bazel.build/versions/master/be/make-variables.html#predefined_genrule_variables</a>: <code>genrule</code> contains an <em>outs</em> parameter.</p>
  
  <p>So the question boils down to this: <strong>is there any way in bazel to reuse (or wrap around) <code>py_test</code> rule and define some output files it will generate?</strong></p>