Module 0: Setup & first test
Welcome to Python for SDETs. This first module gets your machine ready and ends with a
real test passing against a real app. By the end you’ll have Python, a virtual environment,
pytest, and requests installed, TestMarket Lab running locally, and a green test
that proves the whole toolchain works end to end.
🎬 Video coming soon
Module 0: setup at a glance — slide guide Slides — opens in a new tabWhat you’ll install
Section titled “What you’ll install”Four things, in order:
- Python 3 — the language (you likely have it from Fundamentals; we’ll verify).
- A virtual environment (
venv) — an isolated, per-project set of packages. pytest— the test runner that’s the de-facto standard for Python testing.requests— the library we’ll use to call the app’s REST API.
Playwright for Python comes later, in Module 6 — no need to install it yet.
Remember: the toolchain for this course is Python + venv + pytest + requests.
Install and verify Python
Section titled “Install and verify Python”You need Python 3.9 or newer.
-
Check what you already have. Open a terminal and run:
Terminal window python --versionIf you see
Python 3.9.xor higher, you’re set — skip to the next section. On some systems the command ispython3:Terminal window python3 --version -
Install it if missing. Download the installer from python.org/downloads and run it.
-
Verify
pip(Python’s package installer — it ships with Python):Terminal window pip --versionIf
pipisn’t found, trypython -m pip --versioninstead.
Remember: confirm python --version (≥ 3.9) and pip --version before going further —
a broken Python is the #1 cause of setup pain.
Make a project and a virtual environment
Section titled “Make a project and a virtual environment”A virtual environment is a private copy of Python’s package area that belongs to one project. Installing into it keeps this course’s packages separate from everything else on your machine — no version clashes, and you can delete the whole thing by deleting one folder.
-
Make the project folder:
Terminal window mkdir python-sdetcd python-sdet -
Set up the virtual environment (the second
venvis the folder name —.venvis a common convention):Terminal window python -m venv .venv -
Activate it. This is the step people forget — you must activate the venv in each new terminal before installing or running:
Terminal window # Windows (PowerShell).venv\Scripts\Activate.ps1# Windows (cmd).venv\Scripts\activate.bat# macOS / Linux (bash, zsh)source .venv/bin/activateWhen it’s active, your prompt shows
(.venv)at the start.
To leave the environment later, run deactivate.
Remember: a venv isolates one project’s packages. Set it up once (python -m venv .venv), activate every new terminal — the (.venv) prefix tells you it’s on.
Install pytest and requests
Section titled “Install pytest and requests”With the venv active, install the two libraries:
pip install pytest requestsRecord what you installed so anyone (including future you, or CI) can reproduce it:
pip freeze > requirements.txtrequirements.txt now lists the exact versions. Later, a fresh machine rebuilds the
environment with pip install -r requirements.txt.
Quick sanity check that pytest is on the path:
pytest --versionRemember: install into the active venv, then pip freeze > requirements.txt to
pin versions — that file is how CI and teammates get the same setup.
Project layout
Section titled “Project layout”A clean test project starts small. Make a tests/ folder — pytest discovers tests there:
python-sdet/├── .venv/ # the virtual environment (don't commit this)├── tests/│ └── test_smoke.py # your tests live here├── requirements.txt # pinned dependencies└── pytest.ini # pytest configuration (optional, added below)Add a small pytest.ini to mark the project root and point pytest at your tests/ folder, so
a bare pytest (run from the project root) discovers them without you naming the path:
[pytest]# Where pytest looks for teststestpaths = testsRemember: keep tests in tests/, pin deps in requirements.txt, and keep .venv/ out
of version control.
Get the practice app: TestMarket Lab
Section titled “Get the practice app: TestMarket Lab”Every test in this course runs against TestMarket Lab — a small, realistic shop with a
REST API and a web UI. It’s a separate project from your python-sdet folder: the app
runs in one terminal, your tests run in another.
You’ll need Node.js installed to run it (the LTS version). Then,
in a folder outside python-sdet:
git clone https://github.com/TesterBaku/testmarket-labcd testmarket-labnpm installnpm startLeave it running and open http://localhost:3000 — you should see the TestMarket storefront. Confirm the API answers too, in a browser or another terminal:
# In a new terminalcurl http://localhost:3000/api/productsYou should get back a JSON array of products.
Remember: the app runs in its own terminal at http://localhost:3000; keep it
running while you work. /api/reset returns the data to a known starting state.
Your first test
Section titled “Your first test”Time to prove the whole stack works. In your python-sdet project, with the venv active and
TestMarket Lab running, put this in tests/test_smoke.py:
import requests
BASE_URL = "http://localhost:3000"
def test_products_endpoint_is_up(): response = requests.get(f"{BASE_URL}/api/products")
# The request succeeded assert response.status_code == 200
# The body is a JSON array with products in it products = response.json() assert isinstance(products, list) assert len(products) > 0Run it from the python-sdet folder:
pytestYou should see something like:
========================= test session starts =========================collected 1 item
tests/test_smoke.py . [100%]
========================== 1 passed in 0.05s ==========================That single dot after the filename is your passing test. 🎉
If you see Connection refused instead, the app isn’t running — start TestMarket Lab in its
own terminal and try again. If pytest reports “no tests ran,” check the file is named
test_smoke.py (the test_ prefix matters) and the function starts with test_. We’ll
unpack exactly why those names matter in Module 1.
Remember: a passing API smoke test (200 + a non-empty list) proves your whole
toolchain — Python, venv, pytest, requests, and the running app — is wired up correctly.
Key takeaways
Section titled “Key takeaways”- This course uses a real local setup, not a browser runner — the way the job works.
- The toolchain is Python + venv + pytest + requests (Playwright comes in Module 6).
- A venv isolates packages: set it up once, activate in every new terminal, install
there, and
pip freeze > requirements.txtto pin versions. - TestMarket Lab runs in its own terminal at
http://localhost:3000and is what every test targets. - pytest discovers files named
test_*.pyand functions namedtest_*; a passing API smoke test confirms the stack end to end.
Checklist — you should now have: Python ≥ 3.9 verified; a python-sdet project with an
active .venv; pytest and requests installed and pinned in requirements.txt;
TestMarket Lab cloned and running at http://localhost:3000; and tests/test_smoke.py
passing.
In Module 1 we go deep on pytest itself — how tests are
discovered, how assert gives you readable failures, and how to run exactly the tests you
want.