Add pytest-source-root-dir variable
For #35.
Adds a pytest-source-root-dir variable that defaults to nil. When this variable is set, the test paths passed to pytest will be relative to the directory defined by that variable.
I like the idea behind this change but I think it should be reworked a bit. It sounds like what we really want is to avoid the cd WORKING-DIRECTORY aspect based on some config and then allow relative paths based on another config. I'd consider two config options that avoids the initial cd portion and then an allow relative paths config item to use or consider an alternate base.
Let me know if that makes sense! Thanks for looking at this!
@ionrock Thanks for the response! The cd WORKING-DIRECTORY actually works fine for me since in my case, my docker-compose.yml file is in my project root directory. I can see how you might want to be able to customize that though if your docker-compose.yml file is in some project sub-directory.
Is that what you're suggesting I add?
Ah, I see what you're saying. I think in that case, I might rename the config around use-relative-paths or something in that vein rather than using an alternate base that effectively seems to just force using a relative path. Let me know if I've misunderstood things!
I was struggling with naming this config variable. I think use-relative-paths is better but it feels like it should be a boolean setting. What about relative-test-paths-base-dir?
@ionrock and just to be super clear, this is my setup that uses the feature in this PR:
.dir-locals.el:
;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")
((python-mode
(pytest-global-name . "docker-compose run --rm app pytest")
(pytest-cmd-flags . "")
(pytest-source-root-dir . "/path/to/docker/mount/volume/")
so that instead of the default command which does not take into account the container directory structure:
cd /path/to/project/root && docker-compose run --rm app pytest /path/to/docker/mount/volume/relative/path/to/test.py
I'd like the command to be
cd /path/to/project/root && docker-compose run --rm app pytest relative/path/to/test.py
@billiams I added a few comments to clarify what I'm thinking about. Let me know what you think or if you need help with the implementation. It has been a while since I did much elisp but I'm happy to dust off my scratch buffer to help out :)
@billiams I added a few comments to clarify what I'm thinking about. Let me know what you think or if you need help with the implementation. It has been a while since I did much elisp but I'm happy to dust off my scratch buffer to help out :)
@ionrock I really appreciate all your feedback and consideration of the changes I'm proposing. I responded to your comments, LMK if you'd like to discuss further and will definitely take you up on the elisp help if needed since I am by no means an expert.
@ionrock LMK if you'd like me to make any other changes to this. Thanks!