QA Graphic

PyTest Install

Alternative way to install PyTest

PyTest Install Icon

The popular pytest framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries.

Python is a good language to learn. According to the TIOBE and PYPL index, Python is the top programing language with C and Java closely behind.

If your application is Python base, QA Engineers may find that writing automation in Python may lead to a better understanding of the code logic - which in turn will result into better testing.

If your installing PyTest on your local MacBook Pro at work, you may run into issues with permissions. The local IT department may have your computer locked down and some of the installs will require Administrator permissions.

Here are the install instructions if you have limited rights.

PyTest User Install

Use Python3 -m pip to install PyTest and Selenium:

python3 -m pip install pytest --user

python3 -m pip install selenium --user

Sample Test File

Here's a simple code sample to validate the install worked:

#!/usr/bin/env /usr/bin/python3
# Verify the Pytest was installed
import pytest
from selenium import webdriver
import sys
import requests
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from time import sleep
 
def test_google():
	global chrome_driver
	chrome_driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))    
	chrome_driver.get('https://www.google.com/')
	title = "Google"
	assert title == chrome_driver.title
	pageSource = chrome_driver.page_source
	gateway = "Carbon neutral since 2007"
	if not gateway in pageSource:
		pytest.fail( "Google Changed their Webpage")
	chrome_driver.close()

Save this file on your computer, I would recommend saving it in ~/pytest/google.py

Execute Test

To execute this test, open up Terminal:

cd ~/pytest/
pytest --no-header -v google.py

 

About

Welcome to Pytest Tips and Tricks, your go-to resource for mastering the art of testing with Pytest! Whether you're a seasoned developer or just dipping your toes into the world of Python testing, this blog is designed to help you unlock the full potential of Pytest - one of the most powerful and flexible testing frameworks out there. Here, I'll share a treasure trove of practical insights, clever techniques, and time-saving shortcuts that I've gathered from years of writing tests and debugging code.

Schedule

Friday 18 Macintosh
Saturday 19 Internet Tools
Sunday 20 Misc
Monday 21 Media
Tuesday 22 QA
Wednesday 23 Pytest
Thursday 24 PlayWright