Automated testing is a well-known context in the world of testing. It is where the test plans are being executed using script instead of a human.
Python comes with the tools and libraries that support automated testing for your system.
Python Test cases are comparatively easy to write. With the increased use of Python, Python-based test automation frameworks are also becoming popular.
xxxxxxxxxx
# Typical testing
df_transformed =
df_loaded = pd.read_sql("SELECT * FROM clean_stock_data", con=db_engine)
# Compare the two DataFrames to ensure that no data loss happened
print(df_transformed.equals(df_loaded))
### Standard Approach (Any test case is a function and except for fixtures should start with "test_")
### Test - 1
def test_transformed_data():
raw_stock_data = extract("raw_stock_data.csv")
clean_stock_data = transform(raw_data)
assert isinstance(clean_stock_data, pd.DataFrame)
### Test - 2
import pytest
@pytest.fixture()
def clean_data(): # Fixture allows the function name to be used as a variable that holds the return value
raw_stock_data = extract("raw_stock_data.csv")
clean_stock_data = transform(raw_data)
return clean_stock_data
def test_transformed_data(clean_data): # Fixture allows the function-as-variable to be passed in the test
assert isinstance(clean_data, pd.DataFrame)
### Test - 3
def test_transformed_data(clean_data): # Fixture allows the function-as-variable to be passed in the test
assert len(clean_data.columns) == 4 # Check number of columns
assert clean_data["open"].min() >= 0 # Check the lower bound of a column
assert clean_data["open"].min() >= 0 and clean_data["open"].max() <= 1000 # Include other assert statements here
# Note: To run the test, execute command : python -m pytest
xxxxxxxxxx
assert df['col'].dtype == 'int'
assert phone['Phone number'].str.contains("+|-").any() == False
xxxxxxxxxx
Nginx && Docker
docker run -d -t -p 80:80 --name web nginx:latest
docker exec -it web
xxxxxxxxxx
app.use((err, req, res, next) => {
console.error(err.stack)
res.status(500).send('Something broke!')
})