strong-toothbrush-37759
03/13/2022, 8:34 PM./pants test src/core/tests/test_companies.py
for example.
Question #1: In the example-django repo, the tests were placed in a models_test.py
. When I have nested testing folders for submodules of a module, what is the best way to formulate a BUILD file inside of the module? Do I adjust the core
BUILD file with sources=["tests/**/test_*.py"]
or should I not worry at all and let tailor create all the BUILD-files?
Question #2: I’m getting an error which I think tells me that I need to configure root_patterns
correctly. The error is:
Exception: String("Can only merge Directories with no duplicates, but found 2 duplicate entries in :\n\n`pyproject.toml` 1.) file digest=9d7d5d9df3e4ae5a4842a380891776c10adfc04ffdf0d48728db8ff4e7a05943 size=1006 ... 2.) file digest=55e6c945374e7d8f58b1d90e4dc00dee93a906850e953db2512938ead8b84fef size=994
I’m gonna post an example of our project-structure inside the thread here to not spam #C046T6T9U too much. The question is: How do I setup source-roots
correctly? I’ve read the documentation about source-roots a couple of times now, but I’m not really sure what’s the optimal way. Maybe this error is again me missing an error inside of our pyproject.toml
, but I hope it’s not 😅 .fast-nail-55400
03/13/2022, 8:40 PMBUILD
file in each module’s directory with python_sources()
(and python_tests(name="tests")
as applicable.
Note: If you run ./pants tailor
, then Pants will write out these BUILD
files for you automatically.strong-toothbrush-37759
03/13/2022, 8:40 PMsrc/ - This is the django root folder
api/
core/
models/
tests/
test_companies.py - company unit-tests
companies.py
tests/
test_companies.py - company integration-tests
admin.py
apps.py
tasks.py
another_module1/
another_module2/
I’d like to be able to import like this from core.models import Company
. In the past we adjusted the __init__.py
inside of the core/models
folder to look like this:
__all__ = [
# companies.py
"Company",
]
from .companies import (
Company
)
As I understand Pants, this adjustment could be a thing of the past. But that’s a question for another time.
As always: Help is highly appreciated 💚strong-toothbrush-37759
03/13/2022, 8:48 PM./pants tailor
and it created all the necessary BUILD-files for me to start the tests. This is totally fine and I’d like to avoid manually adjusting auto-generated files. In any case this is me asking “should I adjust the generated BUILD-files at all or just let tailor to its job?“.
I think that maybe my root_patterns
need to be adjusted. Right now I don’t have anything setup (which allowed me to start running ./pants test src/core/tests/test_companies.py
although this runs into the error mentioned above).
My roots look like this:
❯ ./pants roots
.
src
fast-nail-55400
03/13/2022, 8:50 PMpyproject.toml
at all?fast-nail-55400
03/13/2022, 8:50 PMpyproject.toml
with different content)strong-toothbrush-37759
03/13/2022, 8:50 PM.
and src/../
strong-toothbrush-37759
03/13/2022, 8:51 PM❯ find . -name 'pyproject.toml' | xargs wc -l
55 ./pyproject.toml
13 ./src/venv/lib/python3.9/site-packages/spacy/tests/package/pyproject.toml
68 total
🤔fast-nail-55400
03/13/2022, 8:52 PMsrc/venv/**
to the --pants-ignore option?fast-nail-55400
03/13/2022, 8:53 PM[GLOBAL].pants_ignore
in the pants.toml
)fast-nail-55400
03/13/2022, 8:54 PMstrong-toothbrush-37759
03/13/2022, 8:55 PM"/src/venv/**",
to the pants_ignore
array but it didn’t change the outcome of the command.strong-toothbrush-37759
03/13/2022, 8:56 PMfast-nail-55400
03/13/2022, 8:57 PMstrong-toothbrush-37759
03/13/2022, 8:59 PMpyproject.toml
if that does matter to somebody: https://pastebin.com/QUz5bT35happy-kitchen-89482
03/14/2022, 12:07 AMhappy-kitchen-89482
03/14/2022, 12:07 AMhappy-kitchen-89482
03/14/2022, 12:09 AMhappy-kitchen-89482
03/14/2022, 12:10 AMhappy-kitchen-89482
03/14/2022, 12:11 AMhappy-kitchen-89482
03/14/2022, 12:12 AMhappy-kitchen-89482
03/14/2022, 12:13 AMstrong-toothbrush-37759
03/14/2022, 6:37 AM❯ ./pants test src/core/tests/test_companies.py --print-stacktrace
07:36:56.15 [INFO] Initialization options changed: reinitializing scheduler...
07:36:56.81 [INFO] Scheduler initialized.
07:37:00.77 [ERROR] 1 Exception encountered:
Engine traceback:
in select
in pants.core.goals.test.run_tests
in pants.backend.python.goals.pytest_runner.run_python_test (src/core/tests/test_companies.py:../tests)
in pants.backend.python.goals.pytest_runner.setup_pytest_for_target
Traceback (no traceback):
<pants native internals>
Exception: String("Can only merge Directories with no duplicates, but found 2 duplicate entries in :\n\n`pyproject.toml`: 1.) file digest=9d7d5d9df3e4ae5a4842a380891776c10adfc04ffdf0d48728db8ff4e7a05943 size=1006:\n\n[tool.black]\nline-length = 100\ntarget-version = [ \"py38\",]\ninclude = \"\\\\.pyi?$\"\nforce-exclude = \"/(\\n .git\\n | .hg\\n | .eggs\\n | .mypy_cache\\n | .tox\\n | .venv\\n | .venv\\n | _build\\n | buck-out\\n | build\\n | dist\\n | migrations\\n)/\\n\"\n\n[tool.isort]\nprofile = \"black\"\nline_length = 100\nsections = [ \"FUTURE\", \"STDLIB\", \"THIRDPARTY\", \"FIRSTPARTY\", \"LOCALFOLDER\",]\nno_lines_before = \"LOCALFOLDER\"\nskip_glob = [ \"*/migrations/*.py\",]\nsrc_paths = [ \"src\", \".\",]\nknown_thirdparty = [ \"django\",]\n\n[tool.coverage.run]\nomit = [ \"*/tests/*\", \"*/migrations/*\", \"*/prototypes/*\", \"*/site-packages/*\", \"*/test_*\", \"scripts/*\", \"docker/*\", \"config/*\", \"pytest.pex/*\",]\nrelative_files = true\n\n[tool.coverage.report]\nprecision = 2\n\n[tool.pytest.ini_options]\npython_files = \"tests.py test_*.py *_tests.py\"\nDJANGO_SETTINGS_MODULE = \"config.settings_testing\"\nmarkers = [ \"slow: marks tests as slow (deselect with '-m \\\"not slow\\\"')\", \"jwt_scope: sets required scope for api test\",]\nenv = [ \"ENVIRONMENT=test\",]\n\n\n`pyproject.toml`: 2.) file digest=55e6c945374e7d8f58b1d90e4dc00dee93a906850e953db2512938ead8b84fef size=994:\n\n[tool.black]\nline-length = 100\ntarget-version = ['py38']\ninclude = '\\.pyi?$'\nforce-exclude = \"\"\"\n/(\n .git\n | .hg\n | .eggs\n | .mypy_cache\n | .tox\n | .venv\n | .venv\n | _build\n | buck-out\n | build\n | dist\n | migrations\n)/\n\"\"\"\n\n[tool.isort]\nprofile = \"black\"\nline_length = 100\nsections = [\"FUTURE\", \"STDLIB\", \"THIRDPARTY\", \"FIRSTPARTY\", \"LOCALFOLDER\"]\nno_lines_before = \"LOCALFOLDER\"\nskip_glob = [\"*/migrations/*.py\"]\nsrc_paths = [\"src\", \".\"]\nknown_thirdparty = [\"django\"]\n\n[tool.coverage.run]\nomit = [\n \"*/tests/*\",\n \"*/migrations/*\",\n \"*/prototypes/*\",\n \"*/site-packages/*\",\n \"*/test_*\",\n \"scripts/*\",\n \"docker/*\",\n \"config/*\",\n]\n\n[tool.coverage.report]\nprecision = 2\n\n[tool.pytest.ini_options]\npython_files = \"tests.py test_*.py *_tests.py\"\nDJANGO_SETTINGS_MODULE= \"config.settings_testing\"\nmarkers = [\n \"slow: marks tests as slow (deselect with '-m \\\"not slow\\\"')\",\n \"jwt_scope: sets required scope for api test\",\n]\nenv = [\n \"ENVIRONMENT=test\",\n]\n")
strong-toothbrush-37759
03/14/2022, 7:29 AM[tool.pytest.ini_options]
section. Whenever this section exists inside of my pyproject.toml
, Pants will throw this error. Weird is that when I comment it out, Pants still recognizes it and throws the same error 😅happy-kitchen-89482
03/14/2022, 5:49 PMstrong-toothbrush-37759
03/14/2022, 5:53 PMhappy-kitchen-89482
03/14/2022, 6:29 PMhappy-kitchen-89482
03/14/2022, 6:29 PMhappy-kitchen-89482
03/14/2022, 6:29 PMstrong-toothbrush-37759
03/14/2022, 6:42 PMstrong-toothbrush-37759
03/14/2022, 7:36 PMhappy-kitchen-89482
03/14/2022, 7:55 PMstrong-toothbrush-37759
03/14/2022, 7:59 PM\\n
with new-lines both files seemed identical.happy-kitchen-89482
03/14/2022, 8:01 PMtarget-version = [ \"py38\",]
and the other has target-version = ['py38']
happy-kitchen-89482
03/14/2022, 8:01 PMstrong-toothbrush-37759
03/14/2022, 8:03 PMstrong-toothbrush-37759
03/14/2022, 8:05 PMinclude = '\.pyi?$'
is causing the error 🙄strong-toothbrush-37759
03/14/2022, 8:06 PMstrong-toothbrush-37759
03/14/2022, 8:13 PM[tool.pytest.ini_options]
python_files = "tests.py test_*.py *_tests.py"
DJANGO_SETTINGS_MODULE= "config.settings_testing"
markers = [
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
"jwt_scope: sets required scope for api test",
]
env = [
"ENVIRONMENT=test",
]
Maybe because of the escaped quotes?strong-toothbrush-37759
03/14/2022, 8:15 PM[tool.pytest.ini_options]
in the pyproject.toml it stops working. Is there some pytest magic trying to parse the file or something? 🤔happy-kitchen-89482
03/14/2022, 8:19 PMpyproject.toml
is relevant to pytest
runs by looking for a tool.pytest
table in the filehappy-kitchen-89482
03/14/2022, 8:19 PMhappy-kitchen-89482
03/14/2022, 8:20 PMhappy-kitchen-89482
03/14/2022, 8:20 PMhappy-kitchen-89482
03/14/2022, 8:20 PMhappy-kitchen-89482
03/14/2022, 8:22 PMhappy-kitchen-89482
03/14/2022, 8:22 PMstrong-toothbrush-37759
03/14/2022, 8:22 PMhappy-kitchen-89482
03/14/2022, 8:22 PMhappy-kitchen-89482
03/14/2022, 8:22 PMstrong-toothbrush-37759
03/14/2022, 8:23 PMhappy-kitchen-89482
03/14/2022, 8:23 PMstrong-toothbrush-37759
03/14/2022, 8:26 PMhappy-kitchen-89482
03/14/2022, 8:26 PMhappy-kitchen-89482
03/14/2022, 8:26 PMhappy-kitchen-89482
03/14/2022, 8:26 PMstrong-toothbrush-37759
03/14/2022, 8:27 PM❯ find . -name 'pyproject.toml' | xargs wc -l
44 ./pyproject.toml
13 ./src/venv/lib/python3.9/site-packages/spacy/tests/package/pyproject.toml
57 total
strong-toothbrush-37759
03/14/2022, 8:28 PM❯ cat ./src/venv/lib/python3.9/site-packages/spacy/tests/package/pyproject.toml
[build-system]
requires = [
"setuptools",
"cython>=0.25,<3.0",
"cymem>=2.0.2,<2.1.0",
"preshed>=3.0.2,<3.1.0",
"murmurhash>=0.28.0,<1.1.0",
"thinc>=8.0.12,<8.1.0",
"blis>=0.4.0,<0.8.0",
"pathy",
"numpy>=1.15.0",
]
build-backend = "setuptools.build_meta"
happy-kitchen-89482
03/14/2022, 8:28 PMhappy-kitchen-89482
03/14/2022, 8:29 PMhappy-kitchen-89482
03/14/2022, 8:29 PMhappy-kitchen-89482
03/14/2022, 8:29 PMhappy-kitchen-89482
03/14/2022, 8:29 PMstrong-toothbrush-37759
03/14/2022, 8:29 PMstrong-toothbrush-37759
03/14/2022, 8:32 PMexample-django
project. Give me a second to upload.strong-toothbrush-37759
03/14/2022, 8:37 PMhappy-kitchen-89482
03/14/2022, 9:48 PM