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

adamant-piano-24321

11/10/2022, 7:52 AM
👋 Hi everyone! I'm having issues running pytest with alembic and pants. It seems the
alembic.ini
file is not being included in the pex runtime. I have attempted to explicitly include the ini file using the file and resource pattern. Still not managing to get this right. Any advice?
w

wide-midnight-78598

11/10/2022, 11:51 AM
Could you provide the associated BUILD file?
h

happy-kitchen-89482

11/10/2022, 4:48 PM
Including the alembic.ini file explicitly sounds right, as dep inference won’t know about it. Whether it should be a
file
or a
resource
depends on how it’s loaded by alembic.
A good way to debug this is to run with
./pants --keep-sandboxes=always
and poke around in the sandbox for the pytest process. You can see if
alembic.ini
is where you expect it to be in the sandbox.
(pants will log the locations of all the sandboxes)
a

adamant-piano-24321

11/15/2022, 6:04 AM
That's great advice! Let me give that a swing
c

cool-yacht-37128

12/21/2022, 8:31 AM
@adamant-piano-24321 Did you ever work this one out?
I'm trying to run alembic from a venv (exported by pants), and despite having the correct PYTHONPATHs for the 1st party roots, I'm getting import errors...
thinking it might be related to your issue
a

adamant-piano-24321

12/21/2022, 8:41 AM
I have indeed! The real trick is to utilise pants listing ability, i.e.:
Copy code
./pants list ::
From this you can see which file with their appropriate path are available to the pants vm. To include a given file, navigate to the BUILD file in that source dir. You then have the option to either include a single or multiple files:
Copy code
file(name="filename", source="filename.yml")
Run list to get the exact file pointer used by pants:
Copy code
./pants list ::
Then where the file is needed:
Copy code
python_tests(
    name="tests",
    dependencies=["path/path:filename"],
)
❤️ 1
Also using
--keep-sandboxes=always
works a charm
c

cool-yacht-37128

12/21/2022, 10:12 AM
It was actually a different issue for me. Turned out that I needed the
prepend_sys_path
config option set in the
alembic.ini
to point to my python first party root for alembic to correctly find the models referenced in my env.py Seems to be something to do with their use of importlib to load modules when using alembic the cli tool
3 Views