rapid-crayon-8232
12/12/2019, 3:45 PMfiles
and adding them as a dependency to the tests but they are still not found or not in the correct path, thx.hundreds-father-404
12/12/2019, 3:47 PMrapid-crayon-8232
12/12/2019, 3:51 PMtests
┣ mocks
┃ ┣ mock1.json
┃ ┣ mock2.json
┃ ┗ mock3.json
┣ snapshots
┃ ┣ __init__.py
┃ ┗ snap_test1.py
┣ BUILD
┣ __init__.py
┣ test1.py
┗ test2.py
rapid-crayon-8232
12/12/2019, 3:52 PMpython_tests(
sources=globs('test_*.py'),
dependencies=[
':mock_files',
'packages-python/package1/data'
],
tags = {'unittest'},
)
files(
name='mock_files',
sources=globs('mocks/*')
)
rapid-crayon-8232
12/12/2019, 3:54 PMFileNotFoundError: [Errno 2] No such file or directory: '/Users/ouailbendidi/XXX/.pants.d/pyprep/sources/f5a7b57cc06b12bc690ae1336634144b46ef5b19/data/tests/mocks/mock1.json'
rapid-crayon-8232
12/12/2019, 3:55 PMmock_path = os.path.join(
os.path.dirname(__file__), "mocks/mock1.json"
)
hundreds-father-404
12/12/2019, 3:55 PMtests/mocks/
rapid-crayon-8232
12/12/2019, 3:56 PMhundreds-father-404
12/12/2019, 3:57 PMglobs
to rglobs
(recursive) for the files entryhundreds-father-404
12/12/2019, 3:58 PMpython_tests
, that’s the default sources for python_tests
already :)rapid-crayon-8232
12/12/2019, 3:59 PMhundreds-father-404
12/12/2019, 4:01 PMrapid-crayon-8232
12/12/2019, 4:11 PMrapid-crayon-8232
12/12/2019, 4:19 PMAh so you want the file name in your tests to be relative to the build rootyou mean that files are mounted, but it's just the path that is incorrect ?
rapid-crayon-8232
12/12/2019, 4:38 PMfiles
are bootsraped:
750f0318a7b1d89c5eab58b4890e97d2c9664b9b
┣ .bootstrap
┃ ┃ ┗ ........
┣ package1
┃ ┣ data
┃ ┃ ┣ tests
┃ ┃ ┃ ┣ __init__.py
┃ ┃ ┃ ┣ test1.py
┃ ┃ ┃ ┗ test2.py
┃ ┃ ┣ __init__.py
┃ ┃ ┣ script1.py
┃ ┃ ┗ script2.py
┃ ┗ __init__.py
┣ packages-python
┃ ┣ package1
┃ ┃ ┗ data
┃ ┃ ┃ ┗ tests
┃ ┃ ┃ ┃ ┗ mocks
┃ ┃ ┃ ┃ ┃ ┣ mock1.json
┃ ┃ ┃ ┃ ┃ ┣ mock2.json
┃ ┃ ┃ ┃ ┃ ┗ mock3.json
┃ ┗ third_party
┃ ┃ ┗ requirements.txt
┣ PEX-INFO
┣ __main__.py
┗ pytestdebug.log
rapid-crayon-8232
12/12/2019, 4:41 PMhundreds-father-404
12/12/2019, 5:00 PMmocks/*
because we directly feed the sources
of a python_tests
into the arguments for Pytest. (We don’t rely on Pytest auto-discovery because it would run over a bunch of unwanted things)
Instead, I believe the solution should look like this:
python_tests(
dependencies=[
':mock_files',
],
tags = {'unittest'},
)
files(
name='mock_files',
sources=rglobs('mocks/*')
)
In your test, you would say open('tests/mocks/mock1.json')
rapid-crayon-8232
12/12/2019, 5:17 PMopen('packages-python/package1/data/tests/mocks/mock1.json')
wich makes sense too because my source_roots
is package-python
hundreds-father-404
12/12/2019, 5:17 PMrapid-crayon-8232
12/12/2019, 5:19 PMhundreds-father-404
12/12/2019, 5:19 PMrapid-crayon-8232
12/12/2019, 5:21 PMrapid-crayon-8232
12/12/2019, 5:21 PMrapid-crayon-8232
12/12/2019, 5:23 PMsnapshottesting
is not supported too then? (https://github.com/syrusakbary/snapshottest)hundreds-father-404
12/12/2019, 5:23 PMresources()
instead of files()
.
Here’s an example of how Pants does this to read in the VERSION
file: https://github.com/pantsbuild/pants/blob/279595cd5f0350726a1da3920e5d9bb392bce926/src/python/pants/BUILD#L54 and https://github.com/pantsbuild/pants/blob/279595cd5f0350726a1da3920e5d9bb392bce926/src/python/pants/version.py#L17rapid-crayon-8232
12/12/2019, 5:35 PMrapid-crayon-8232
12/13/2019, 8:51 AMsource_roots
is defined as :
source_roots: {
'packages-python': ('python',)
}
so my package1
is bootstrapped directly as package1/data/tests
in the test env, while the ressource are bootstrapped as packages-python/package1/data.tests/mock
rapid-crayon-8232
12/13/2019, 10:37 AM[source]
source_roots: {
'packages-python': ('python',)
}
test_roots: {
'packages-python': ('python',)
}
rapid-crayon-8232
12/13/2019, 10:37 AMpants.ini
, thanks @hundreds-father-404 🙂hundreds-father-404
12/13/2019, 3:03 PM