- First create a new conda environment. Please specify python version as 3.9.
conda create -n <envname> python=3.9
. - Activate the env you created.
- Set environment variable
PYTHONPATH
in your new conda environment.conda env config vars set PYTHONPATH=<path-to-src\promptflow>
. Once you have set the environment variable, you have to reactivate your environment.conda activate <envname>
. - In root folder, run
python scripts/building/dev_setup.py --promptflow-extra-deps azure
to install the package and dependencies.
dev-connections.json.example
is a template about connections provided in src/promptflow
. You can follow these steps to refer to this template to configure your connection for the test cases:
cd ./src/promptflow
- Run the command
cp dev-connections.json.example connections.json
; - Replace the values in the json file with your connection info;
- Set the environment
PROMPTFLOW_CONNECTIONS='connections.json'
;
After above setup process is finished. You can use pytest
command to run test, for example in root folder you can:
- Run all tests under a folder:
pytest src/promptflow/tests -v
- Run a single test:
pytest src/promptflow/tests/promptflow_test/e2etests/test_executor.py::TestExecutor::test_executor_basic_flow -v
- Set up your python interperter
- Open the Command Palette (Ctrl+Shift+P) and select
Python: Select Interpreter
.
- Select existing conda env which you created previously.
- Set up your test framework and directory
- Open the Command Palette (Ctrl+Shift+P) and select
Python: Configure Tests
.
- Select
pytest
as test framework.
- Select
Root directory
as test directory.
- Click the
Run Test
button on the left
- Set up your pycharm python interpreter
- Select existing conda env which you created previously
- Run test, right-click the test name to run, or click the green arrow button on the left.
- Put all test data/configs under
src/promptflow/tests/test_configs
. - Write unit tests:
- Flow run:
src/promptflow/tests/sdk_cli_test/unittest/
- Flow run in azure:
src/promptflow/tests/sdk_cli_azure_test/unittest/
- Flow run:
- Write e2e tests:
- Flow run:
src/promptflow/tests/sdk_cli_test/e2etests/
- Flow run in azure:
src/promptflow/tests/sdk_cli_azure_test/e2etests/
- Flow run:
- Test file name and the test case name all start with
test_
. - A basic test example, see test_connection.py.
Currently all tests are under src/promptflow/tests/
folder:
- tests/
- promptflow/
- sdk_cli_test/
- e2etests/
- unittests/
- sdk_cli_azure_test/
- e2etests/
- unittests/
- sdk_cli_test/
- test_configs/
- connections/
- datas/
- flows/
- runs/
- wrong_flows/
- wrong_tools/
- promptflow/
When you want to add tests for a new feature, you can add new test file let's say a e2e test file test_construction.py
under tests/promptflow/**/e2etests/
.
Once the project gets more complicated or anytime you find it necessary to add new test folder and test configs for
a specific feature, feel free to split the promptflow
to more folders, for example:
- tests/
- /
- e2etests/
- test_xxx.py
- unittests/
- test_xxx.py
- e2etests/
- test_configs/
- /
- /