-
Notifications
You must be signed in to change notification settings - Fork 26
Add pytest-source-root-dir variable #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
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 Let me know if that makes sense! Thanks for looking at this! |
|
@ionrock Thanks for the response! The 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 |
|
@ionrock and just to be super clear, this is my setup that uses the feature in this PR: ;;; 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.pyI'd like the command to be cd /path/to/project/root && docker-compose run --rm app pytest relative/path/to/test.py |
README.org
Outdated
|
|
||
| To override this behavior, set an optional source root directory: | ||
| #+BEGIN_SRC elisp | ||
| (setq pytest-source-root-dir "/base/path/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I think we should keep this variable. Let me know what you think of this example.
My code is in ~/Projects/myapp and I mount things in docker under /opt/myapp. If I have pytest-source-root-dir (which could probably be named a little clearer but I don't have a better idea now) that means I can say I want replace the WORKING-DIRECTORY with the pytest-source-root-dir when figuring out the relative path.
For example the /project/root/path/to/test.py using a /opt/myapp would replace the /project/root with /opt/myapp. An alternative is that you use can allow a pytest-use-relative-test-paths boolean that does the behavior you're defining with your existing code.
Let me know if that makes sense and handles your use case clearly!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're just solving the running-individual-tests-in-docker problem, then my preference would be to provide one simple solution to fixing test paths in the test environment when they don't match up with the absolute path in the local environment. For my use-case, I have no need to customize the local project root, but I could see how someone might want to do that (i.e. the case where docker-compose config is not at the project root). However, I wanted to avoid over-complicating the changes I'm making to this project unless users explicitly needed that additional functionality.
My understanding of pytest is that passing in a relative test path defined from the current working directory is equivalent to passing in a correct absolute path. Since that is the case, it is more durable to pass in the relative path, since any changes to your container's working directory would necessitate a change to any hardcoded container base path if you are setting an absolute path.
I propose keeping it simple and sticking with the current setup of one additional optional string variable, which I should rename to something that makes more sense to you. Do you agree?
pytest.el
Outdated
| (tnames (mapconcat (apply-partially 'format "'%s'") tests " ")) | ||
| (tnames | ||
| (mapconcat | ||
| (if pytest-source-root-dir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on my comments above, this may need to adjust slightly to consider the boolean and what root to use when finding the relative path.
|
@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! |
For #35.
Adds a
pytest-source-root-dirvariable that defaults tonil. When this variable is set, the test paths passed to pytest will be relative to the directory defined by that variable.