Part 2. Framework Structure


In this section, we will create our project along with the Python packages it needs and the appropriate framework structure

Let’s begin 🙂


Pipenv is a tool that aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the Python world. It handles all our Python packages as well as creating our virtual environment in a new shell.

Installing Pipenv

  1. Enter the following command to install pipenv via pip on the user level, to prevent breaking any system-wide packages.

Setting up Pipenv Shell

Next, let’s set up our virtual environment in a new shell

  1. Open up a Terminal (or Command prompt) and change directory in to your project root…
  2. Enter the following command to create the virtual environment shell…

Installing our Python packages

We will now use pipenv to install our Python packages locally to our project.  This way, any one else who clones our repository can easily install all necessary packages listed in our Pipfile by entering pipenv install 🙂


  1. Enter the following command, whilst in the root of the project to install the pytest-bdd framework…


  1. Enter the following command, whilst in the root of the project to install selenium


  1. Enter the following command, whilst in the root of the project to install webdriver-manager, which will automatically manage our webdriver binaries for us…

Now, we can open up our project in our chosen IDE, so let’s do that 🙂

Framework Structure

Good practice when using pytest-bdd is to create a parent test directory, and then have features and step_defs sub-directories/python packages contained within the test directory.

  1. Add the following directories and python packages so that your project tree looks the same/similar to below…

Creating our ConfTest file

Next, we will create our python file which will contain our setUp and tearDown functions for our webdriver

  1. In the test python package, add a new Python file and name it (this is where we will store our shared steps and fixtures)
  2. Add the following in the file (I have added comments to explain what is going on)…

The foundations are now setup.  In the next section, we will begin writing our first BDD scenario 🙂

Liked it? Take a second to support Thomas on Patreon!

Previous Article

Next Article

2 Replies to “Part 2. Framework Structure (PyTest-BDD)”

  1. Hey man! We connected on LinkedIn and I’ve since discovered your blogs/articles here. I wanted to point something out (at least for mac users); for me:
    pip install –user pipenv
    caused issues with being able to run pipenv shell in any other directory. I found that this helps install it globally:
    sudo -H pip install -U pipenv

    Thanks for this article!

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.