Allow for setting sys.path in protostar.toml
See original GitHub issueAs mentioned in discord, I’d like to import my own python functions in hints. This is currently not straightforward because I have to manipulate sys.path
.
What I’ve currently settled on is to do the path manipulation in __setup__
and imports in the hints themselves.
@external
func __setup__():
%{
import os, sys
sys.path.append(os.path.abspath(os.path.dirname(".")))
%}
return ()
end
@external
func test_foo():
# ...
local expected
%{
from tests.my_module.utils import my_func
ids.expected = my_func(42)
}%
# ...
end
It works, but could be made better.
One suggestion is to automatically have the directory in which the test_foo.cairo
file is located placed in sys.path
so that I can have utils.py
sitting in the dir structure right next to my test files. Another thing that would be beneficial is to have a config setting in protostar.toml
where I could list paths that I want to have added to sys.path
for each test file so that I don’t have to manipulate the path inside __setup__
.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Testing | Protostar - Software Mansion
Protostar provides a flexible testing environment for Cairo smart contracts. It allows to write unit/integration tests with a help of cheatcodes.
Read more >The initialization of the sys.path module search path — Python ...
A module search path is initialized when Python starts. This module search path may be accessed at sys.path. The first entry in the...
Read more >Check and add the module search path with sys.path in Python
In Windows, you can add PYTHONPATH as well as normal environment variables by right-clicking on your PC (My Computer) -> System -> System...
Read more >The Module Search Path - Real Python
In this video, you're going to explore the module search path. ... contained in the PYTHONPATH environment variable, if it is set.
Read more >jedi.api.project — Jedi 0.18.2 documentation - Read the Docs
Projects can be saved to disk and loaded again, to allow project definitions to be used across repositories. """ import json from pathlib...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@milancermak you should be able to execute your original code in the newer protostar versions, since the root of the project is added to
cairo-path
. This might not work with additional CLI’s--cairo-path
just yet, i’m going to start doing some work on that.This should be possible right now, since pythonpath is being synced with cairo-path