forked from conan-io/conan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
import conanfile just once (conan-io#4095)
* import conanfile just once * reset cache * fixing tests * review
- Loading branch information
1 parent
4387a77
commit f237ad8
Showing
4 changed files
with
48 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import unittest | ||
|
||
from conans.test.utils.tools import TestClient | ||
|
||
|
||
class OptimizeConanFileLoadTest(unittest.TestCase): | ||
|
||
def test_multiple_load(self): | ||
""" when a conanfile is used more than once in a dependency graph, the python file | ||
should be read and interpreted just once, then instance 2 different ConanFile | ||
objects. The module global value "mycounter" is global to all instances, this | ||
should be discouraged to use as if it was an instance value. | ||
In this test there are 2 nodes "Build/0.1" as it is a build-requires of both the | ||
conanfile.py and the test_package/conanfile.py | ||
""" | ||
client = TestClient() | ||
conanfile = """from conans import ConanFile | ||
mycounter = 0 | ||
class Pkg(ConanFile): | ||
mycounter2 = 0 | ||
def configure(self): | ||
global mycounter | ||
mycounter += 1 | ||
self.mycounter2 += 1 | ||
self.output.info("MyCounter1 %s, MyCounter2 %s" % (mycounter, self.mycounter2)) | ||
""" | ||
client.save({"conanfile.py": conanfile}) | ||
|
||
client.run("create . Build/0.1@user/testing") | ||
|
||
client.save({"conanfile.py": conanfile, | ||
"test_package/conanfile.py": conanfile + " def test(self): pass", | ||
"myprofile": "[build_requires]\nBuild/0.1@user/testing"}) | ||
|
||
client.run("create . Pkg/0.1@user/testing -pr=myprofile") | ||
self.assertIn("Build/0.1@user/testing: MyCounter1 2, MyCounter2 1", client.out) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters