pytest-el icon indicating copy to clipboard operation
pytest-el copied to clipboard

Add pytest-source-root-dir variable

Open billiams opened this issue 3 years ago • 8 comments

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.

billiams avatar Jun 30 '22 19:06 billiams

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 avatar Jul 06 '22 19:07 ionrock

@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?

billiams avatar Jul 06 '22 19:07 billiams

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!

ionrock avatar Jul 06 '22 20:07 ionrock

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?

billiams avatar Jul 06 '22 21:07 billiams

@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 avatar Jul 06 '22 21:07 billiams

@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 avatar Jul 07 '22 04:07 ionrock

@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.

billiams avatar Jul 07 '22 18:07 billiams

@ionrock LMK if you'd like me to make any other changes to this. Thanks!

billiams avatar Sep 25 '22 21:09 billiams