-
Notifications
You must be signed in to change notification settings - Fork 0
Setup the project
For Windows: https://www.python.org/downloads/windows/
Download Windows installer (64-bit)
with the latest version for a particular OS (recommend at least 3.11
). While installing, a recommendation to follow the below configs
Customize installation allows us to set a custom path for installation, and all users can use the Python
If you forgot to tick the Add Python to environment variables
checkbox, you can add it to your environment variable PATH by following these steps. For example, Python is installed to C:\Softwares\Python
, via the command line you can add to the system PATH
$Env:Path += ";C:\Softwares\Python\;C:\Softwares\Python\Scripts\"; setx -m PATH "$Env:Path"
Without command line, you can follow these steps:
Search for Edit the system environment variables
Go to Advanced
> Environment Variables
Under the section System variables
> variable Path
, add 2 new lines for Python. For example
To verify that Python is installed successfully, you can open CMD and execute the command; it should return the correct version.
python --version
There are multiple ways to install Poetry (refer to: https://realpython.com/dependency-management-python-poetry/)
In most cases, the recommended way to install Poetry is with the help of pipx
, which takes care of creating and maintaining isolated virtual environments for command-line Python applications. It is also common for both Windows and Unix
python -m pip install pipx
Now, install poetry
by using pipx
pipx install poetry
Following pipx
instructions for the first configuration needed. poetry
is now globally available.
poetry --version
References:
Also, installing the virtual
package enables the creation of isolated local virtual environments for Python projects. Virtual environments help avoid package conflicts and enable choosing specific package versions per project.
pipx install virtualenv
Using PyCharm (Community Edition) as the IDE
- Windows: https://www.jetbrains.com/pycharm/download/?section=windows
- Unix: https://www.jetbrains.com/pycharm/download/?section=linux
Refer to Poetry CLI usage: https://python-poetry.org/docs/cli/
- If you have not created the project yet. Create a new project by using the
new
command followed by project's folder name and the first package. For example
poetry new test-automation-fwk-python --name ndviet-test-automation
-
If the first package name is same as the project name, skip to set argument
--name
-
If you have created an empty directory for the project, this command will help you create a
pyproject.toml
and the first package
poetry init --name ndviet-test-automation
- Configure the virtual environment in the project, and create it automatically if it isn't exist.
poetry config --local virtualenvs.create true
poetry config --local virtualenvs.in-project true
For any config --local
it will be added to poetry.toml
which is the local configuration file for Poetry instances.
- To read the
pyproject.toml
file from the current project, resolves the dependencies, and installs them
poetry install
With the virtual env created in the project by Poetry, once the project is opened in IDE, the IDE can configure the base interpreter by using .venv
itself.
We created and successfully activated the project with the isolated virtual environment. We can add more dependencies to the project via Poetry command add
.
For example, if the project is empty, and you are starting from scratch, run the poetry add
command below one by one to install these essential libraries. Or you can add it to pyproject.toml
under section [tool.poetry.dependencies]
, then perform poetry install
once.
poetry add robotframework
poetry add robotframework-pythonlibcore
poetry add selenium
Those dependencies will be installed in project .venv
.
One good practice is to save the project dependencies in a requirements.txt
file. With Poetry project, to create a requirements.txt
file from the poetry.lock
file, you can use the following command:
poetry export --without-hashes --format=requirements.txt --output=requirements.txt
If while working on the project, you decided to add more libraries, you can re-run the same command to export the newly added libraries.
If you decide to set up the same project on a different machine, or the project with existing, you can install all the same dependencies. Just simplify to run the command
poetry install
Create a .gitignore
file to ignore Virtualenv
resources and others to reduce the size of the project before pushing to SCM. For example .gitignore
contains
.venv
.idea
poetry.lock
You are able to install globally robotframework-ride
and launch the RIDE (the IDE exclusive for Robot Framework tests).
pipx install robotframework-ride
ride.py