https://pantsbuild.org/ logo
#general
Title
# general
c

cold-vr-15232

09/27/2022, 10:17 AM
Hi! I'm not sure if it's something I do wrong or if there is an issue: I started using a Python monorepo, and some of the test modules in different applications have the same name. Running mypy via "./pants check ::" gives an error because of that. Is there a way to get around that? I tried running separately on each source root, but that's one level too high, would need to list all directories under each root also.
b

bitter-ability-32190

09/27/2022, 11:08 AM
Mypy thinks your code is using implicit namespace packages. Slap some
__init__.py
files in the complaining directories and you'll be good to go
c

cold-vr-15232

09/27/2022, 11:48 AM
Unfortunately, that creates other conflicts elsewhere. I think I will have to restructure the projects. It will take a while until the whole monorepo change settles. Thanks!
w

wide-midnight-78598

09/27/2022, 12:00 PM
Whats the error? And what's your mypy config?
c

cold-vr-15232

09/27/2022, 12:14 PM
No, if I make the tests directory a package, the conflicts are outside of mypy. There are duplicate package names, and I will probably have to change those. It's a good thing the project is just starting and there's not a lot of changes.
h

happy-kitchen-89482

09/27/2022, 2:00 PM
Is it just the module name that collides (e g. foo_test.py) or the full path from the source root (e g. path/to/foo_test.py)?
Generally, colliding module basenames are fine but colliding full dotted names can cause trouble, regardless of Pants
b

bitter-ability-32190

09/27/2022, 2:48 PM
Yeah IIUC it's an issue with mypy assuming all the files it's been given represent one big project 🫤 There might be mypy settings around it
c

cold-vr-15232

09/27/2022, 3:15 PM
It's weird that it is recommended to not have the tests folder as a package (no init.py) but then one can't easily have utility modules alongside the test_* ones. If thre is no package, the modules are assumed to be top-level and then if two apps have for example test_main.py, then there is a conflict.
b

bitter-ability-32190

09/27/2022, 3:23 PM
Python packaging has many quirks 😛
We just do the "tests next to code" thing
3 Views