Using breakpoint() in Python3

Use Python’s breakpoint() function to easily step through your code.

The breakpoint() function was added in Python 3.7 and is part of Python’s built-in functions.

Using breakpoint() is as simple as adding it to your script and running the script.

Here is a simple example using flask.

from flask import Flask


app = Flask(__name__)

@app.route("/")
def index():
    breakpoint()
    return "Hello, breakpoint()!"

After starting the flask application, your terminal will be in a pdb instance and you can start debugging. Use the continue command to break out of the debugger and let the code continue executing. Use next to step to the next line of code.

References

Python 3 Virtual Environment Tips

Tips for creating and using virtual environments in Python 3.

Create a virtual environment

Create a virtual environment with the current Python3 version.

python3 -m venv <directory>

This will create a virtual environment for the given directory.

Example:

python3 -m venv venv
Activate a virtual environment

If you created a virtual environment from the Create a virtual environment snippet, you can activate a virtual environment for the created virtual environment directory.

source <virtual_environment_directory>/bin/activate

Example:

source venv/bin/activate
Deactivate a virtual environment

Use the deactivate command to exit the virtual environment.

deactivate
References

Get All Orders For A Product In WooCommerce

Over the last year I have spent a good amount of time working with multiple WooCommerce powered websites. As the application becomes more complex, I am finding myself digging deeper into WooCommerce to find out how (or why) something works. I received a feature request that would require finding all orders for a product.

Continue reading “Get All Orders For A Product In WooCommerce”

What To Do With A New Laravel Project

During the process of learning Laravel, I taken up the habit of creating many test applications for new features and ideas. With each new Laravel install, I find myself having to take the time to set up the same thing in each application. This process is becoming tedious as I have to dig through the documentation every time. I decided to document this process to save me some time with each new Laravel install.

Continue reading “What To Do With A New Laravel Project”

Using In-Memory SQLite Database During Unit Tests In Laravel

I came across an issue when running unit tests in Laravel where my unit tests where altering my local SQLite database. I discovered the issue was due to the sharing of .env files. It turns out the solution is as simple as adding a single environment variable to your phpunit.xml file.

Continue reading “Using In-Memory SQLite Database During Unit Tests In Laravel”