-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[question] How to get environment variable from the tested reference to the test_package test()? #3876
Comments
Hi @Adnn Thanks for your report. I am not sure what could be failing. This is intended to work relatively simply, sorry for the lack of documentation, the idea is that besides the I have just tried with this unittest in Windows and it works: def test_runenv_info_test_package_access():
c = TestClient()
lib = textwrap.dedent("""
from conan import ConanFile
class Lib(ConanFile):
name = "lib"
version = "0.1"
def package_info(self):
self.runenv_info.define("MY_TEST_LIBVAR", "MY_TEST_LIBVALUE")
""")
test_package = textwrap.dedent("""
from conan import ConanFile
class TestTool(ConanFile):
settings = "os"
def requirements(self):
self.requires(self.tested_reference_str)
def test(self):
self.run("set", env="conanrun")
""")
c.save({"conanfile.py": lib,
"test_package/conanfile.py": test_package})
c.run("create .")
assert "MY_TEST_LIBVAR=MY_TEST_LIBVALUE" in c.out Note that the Also finally, please note that the $ set SOME_VAR=value && echo %SOME_VAR%
%SOME_VAR%
$ echo %SOME_VAR%
value Because it is not evaluated, it is just replaced verbatim in the command line from env-vars, but before the actual evaluation of the command line. This is why the second time it works, because the env-var was previously defined. This is why the test above with |
Hi @Adnn Did you manage to see my test above? Any further feedback that could help? Thanks! |
Hi @memsharded, As usual, thank you very much for taking the time to give an answer which is both practical and give some interesting details.
What was failing was what you pointed out at the end: an inline command provided to Having recently been in the position of the frustrated neophyte, I will use the occasion to report what I think could have made me sort it out without bothering you on the issue tracker: Windows limitation
Imho, this was the biggest problem: what feels like the canonical way to consume an env-var - and the simplest/shortest test of this feature - is to self.run() env parameterIn the page you pointed out was https://docs.conan.io/2/reference/tools/env/envvars.html#running-with-environment-files, which is a good explanation of the Thanks again for you help! |
Yes, I agree. Windows is particularly confusing in this regard, not so many people are aware of how it works.
One of the major "blocker" or problems that Conan generated in Conan 1 that users could not fix is that Conan 1 was automatically and by default activating the environment before calling the recipe methods. So This is why the new "environment" management (introduced in Conan 1) uses always environment scripts that can be activated ,deactivated, changed, added etc directly from the consumer code, and use different environments for different But I agree that this can create this confusion with the Windows env-var evaluation process. |
What is your question?
Hi!
We are porting a recipe which is publishing an env var (in its
package_info()
), and this variable is tested by the test_packagetest()
method.We read several pages from the documentation:
But none seems to indicate any limitation regarding the run environment not being propagated to the
test()
method, nor any specific requirement to retrieve environment variables.(side note: the doc for
conanfile.run()
mentions anenv
parameter, but does not describe it).Due to this lack of guidance, we tried several approaches in the upstream to try and forward the env var:
And made several attempts to retrieve
WIX
orPATH
environment variables:Sadly, the
WIX
variable remains undefined, and thePATH
variable is not appended with the value ofbindir
.Accessing the package environment from its test package would seems like a common requirement, yet as you could probably infer it generated a lot of frustration and confusion.
Have you read the CONTRIBUTING guide?
The text was updated successfully, but these errors were encountered: