Update sys.path when running memray run#86
Conversation
In order to match the behavior of `python foo.py`, `python -m foo`, and `python -c "foo"`, `memray run` manipulates `sys.path` and `sys.argv[0]` to match the modifications that the interpreter itself would do. Add tests validating that the modifications work as expected. Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
This enables finding local modules. Also, ensure that `sys.argv[0]` matches what it would if the user had run this command without Memray, to minimize the observeable differences our runner forces on users' scripts. Signed-off-by: tal66 <77445020+tal66@users.noreply.github.com> Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
|
Thanks @tal66 - I picked this up, but ran in a bit of a different way with it. In particular, the reason you were struggling with mocks in the tests was that you were putting the new tests into the wrong layer - the tests in the The tests that we need in order to validate that this is working properly fit better into the @pablogsal Since I've made some pretty extensive changes here, I'd rather not land this myself - would you mind giving this a review? |
|
Thanks for adding tests for all three cases :) |
Hi, this closes #76.
test_cli.py::TestRunSubCommand(class level mocks limited testing possibilities)edit_systhat edits sys.path (also moved existing sys edits to it).sys.path[0] will be the directory containing args.script, or
'.'whenrun -c(like python does)