:wave: Hi everyone! I'm having issues running pyt...
# general
a
👋 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
Could you provide the associated BUILD file?
h
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
That's great advice! Let me give that a swing
c
@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
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
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