I am currently using ```__defaults__( { ...
# general
l
I am currently using
Copy code
__defaults__(
    {
        (
            python_sources,
            python_source,
            python_test,
            python_tests,
            python_test_utils,
        ): {"run_goal_use_sandbox": False}
    }
)
in a part of my project. Now I have a issue that if I run a python source it works perfectly fine. All files I require during runtime (relative to the source) are found. If I run
Copy code
pants test ::
The
python_test
,
python_tests
, and
python test_utils
goals are still run in a sandbox. Hence, the tests fail because the paths can not be found. Does anyone have a solution for this issue?
r
Can you try it with putting it inside the pants.toml? If that works then the bug is in the
___defaults___
Copy code
[python]
run_goal_use_sandbox = False
l
Tried it with
default_run_goal_use_sandbox = false
, same issue.
r
Did you mean you tried with what I suggested? Where did you find
efault_run_goal_use_sandbox = false
in docs?
l
Copy code
[python]
default_run_goal_use_sandbox = false
This is the setting for the global python config: https://www.pantsbuild.org/docs/reference-python#basic-options
r
I was suggesting based on this https://www.pantsbuild.org/docs/reference-python_tests#coderun_goal_use_sandboxcode Although now I don't know why both of these options exist
l
They are the same. Yours is for a goal based configuration the other implies it being the default for all python goals.
r
What I am bit confused is it stresses
run
Run is generally used for running some application/binary
Copy code
pants run <some.pex>
tests are just own target, we don't do
Copy code
pants run <test>
l
True, but if i can run a file without sandbox mode I should be able to also test it without sandbox mode.
r
Yeah so maybe there is some other way for it or maybe not. The option you are using is only for runnable targets
Although docs are confusing.
l
But I checked the source code
python_tests
it is not implemented there.
r
They most probably copy some internal doc template and don't distinguish between runnable target and non-runnable ones.
This has happened in past also. So it's still an issue that needs to be fixed i.e. targets sharing some common doc template.
l
You mean the documentation being wrong, or the behaviour?
In my opinion tests should be able to be run with something like
use_sandbox = false
. Hence, one is not able to test sources supposed to be run outside of a sandbox.
r
Doc being wrong. As you said the source code doesn't have the implementation
l
I am not sure how the test runner handles
python_sources
or if they are handled at all. But as a user I would expect that if I set
run_goal_use_sandbox = False
in a
python_source
that
python_test
would respect that configuration.
r
But I think you are confusing between what is
run
and what is
test
as a goal.
run
is only applicable for
python_sources
. The
python_test
doc shouldn't mention its usage. Whether such feature should exist or not, I would agree it should but it would be some other option like you said
use_sandbox
or something
Please make an issue citing your use case?
l
Yes, I know, but
test
as a goal should test runnable goals. I will open an issue.
🙏 1
b
So this is actually not a bug, and is all as designed, although for the test goals it could maybe be better called out. Here's the gist: • The run goal is analogous to running a python file
python <file.py>
. You can run any python files including test ones, so therefore it inherits the field • The test goal specifically maps to running pytest on the file. And therefore the code isn't being run via the run goal and doesn't inherit this flag • The run goal runs the process, no matter what. Therefore it's ok to run in your source tree, since we aren't trying to cache any results. • The test goal is always run in the sandbox, because the results are cached. If we allowed running outside the sandbox, those cached values could be inconsistent with the state of your files, and that breaks a fundamental guarantee of Pants.
l
I get that it is designed that way. Now the question is how do I test my code. It runs perfectly in non sandbox mode, as it is supposed to. The test will always fail. I could try to include the required files at the required locations to make it testable. This seems quite hacky…
b
If your test is complaining about missing files, those files, and the dependency from your code to those files must be made known to Pants. That's how pants knows when the cache key for the test is invalidated (and what files belong in the sandbox)
l
Ok! So I will just add the files as resources for the tests.