Giter Site home page Giter Site logo

dockerized-pytest-course's Introduction

pytest_project

Prerequisites

Install Docker

  • These tests have been packaged to run with all dependencies installed within a Docker container. Due to the use of f-strings, this must be run with python 3.6+. The Docker image is based on python 3.7

Usage

To run open a shell

$ docker-compose build
$ docker-compose run test sh

This will open the docker shell and you can run one of the following commands:

Run the entire test suite

$ pytest 

Run the tests for a certain file matching a keyword

$ pytest -k <test_file_name>

Run tests while printing all variables and verbose output

$ pytest -vvl

To exit the shell

$ exit

Debugging

  1. If you page up (ctrl + fn) within the debug output when running pytest -vvl or when encountering test errors, your cursor may stick and be unable to continue writing in the docker shell. You can get past this by typing q to return to entry mode in the docker container.

  2. If you'd like to debug a piece of code, you can add either of the following built-in functions to a section of the code to enter into the pdb debugger while running pytest.

    • breakpoint() (python 3)
    • import pdb; pdb.set_trace() (python 2)

Additional Practice

  • Try to create a Map class that assembles the points you've created into a data structure. Create one test to make sure the map has the appropriate points and create another test to raise an exception if you assert the Map has a point that it has not stored.

  • Write a simple xml or json data processor to our data_processor.py file. After doing so, update the factory fixture to also allow a user to pass in the data for testing. There's a json_processor.py file in the scripts file if you get stuck and want to compare what you've done to a sample json reader.

  • Create a User class. Each User should have a height and favorite color. Based on their height, create a function that awards them different types of candy. Try working from the test first as you add this functionality and think of ways to parametrize your test.

  • Find open source Python projects that use pytest and read their tests. Then go to the source code to validate your assumptions. Try doing this repeatedly over a few projects that use the pytest framework. Here are a few to get you started:

  • Add validation to the delete function in the fitness log class. First, refactor your test to account for this.

  • Additionally, you may consider contributing to open source projects that use pytest. If you are new to open source, there are several resources to get started.

  • The awesome for beginners github repository and the first timers only website contain ideas for beginner-friendly open source contributions.

  • Also, the mediawiki parser library lists issues perfect for someone looking to get started with open source contributions to their project.

Feedback

  • After watching the course, if you have any feedback, I'd love to hear from you! Please make an issue on this repository, and I will get back to you.

dockerized-pytest-course's People

Contributors

coding-geographies avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dockerized-pytest-course's Issues

Installation and Setup for Ubuntu Linux

Installation and Setup for Ubuntu Linux

Title: Docker and VS Code

Description: It seems like it would be a good idea to have an installation and setup video for Ubuntu Linux in addition to the ones already provide.

Logic error in condition for nested _specify_type function within the process_data factory fixture

Chapter 3 Video 2

Title: Factory fixtures

Description: The current condition meant to determine whether or not to read a CSV or JSON file will lead to always trying to read CSV files.

See PR #1. The _specify_type function is a bit confusing in that it seems to be communicating that it's able to find a file based on its filename or file type, when in reality it only needs to do a search for a given filename and use the appropriate file processor to read the file based on the file's type.

Example

def _specify_file(filename):
    files = os.listdir(city_list_location)

    for f in files:
        if filename == f:
            if filename.endswith('.json'):
                data = data_processor.json_reader(city_list_location + f)
            elif filename.endswith('.csv'):
                data = data_processor.csv_reader(city_list_location + f)

             return data

Feedback

Chapter 3 Video 3

Title: Parametrization

Description: The code in the video did not show how to update the test function's signature after implementing parametrization.

Example

FROM

def test_altitude_stat_per_country(process_data):
    ....

TO

@pytest.mark.parametrize('country,stat,expected', [
    (....),
    (....)
])
def test_altitude_stat_per_country(process_data, country, stat, expected):
    ....

Chapter 3 Video 2

Title: Factory fixtures

Description: The current condition meant to determine whether or not to read a CSV or JSON file will lead to always trying to read CSV files.

See PR #1. The _specify_type function is a bit confusing in that it seems to be communicating that it's able to find a file based on its filename or file type, when in reality it only needs to do a search for a given filename and use the appropriate file processor to read the file based on the file's type.

Example

def _specify_file(filename):
    files = os.listdir(city_list_location)

    for f in files:
        if filename == f:
            if filename.endswith('.json'):
                data = data_processor.json_reader(city_list_location + f)
            elif filename.endswith('.csv'):
                data = data_processor.csv_reader(city_list_location + f)

             return data

Misc

In some places we return from fixture functions and in others we yield, but there's no explanation for why we do one or the other.

[nit] In Chapter 2 Video 2 we introduce how to mark instance variables as private, but did not keep the instance variables for the Point class private for the videos following.

[nit] In Chapter 2 Video 4 we expected a ValueError to be raised where a TypeError would have been more appropriate. This is minor as the essential lesson on how to test for exceptions is not lost.

Problem configuring docker during "docker-compose run test sh" command

I've been following the LinkedIN video course: "Python Unit Testing with Pytest" and ran into a problem configuring the docker container while running "docker-compose run test sh"
which is at the 5:14 mark in the Docker and VS Code (PC) video.

ERROR: Cannot create container for service test: status code not OK but 500: {"Message":"Unhandled exception: Filesharing has been cancelled","StackTrace":" at Docker.ApiServices.Mounting.FileSharing.d__6.MoveNext() in C:\workspaces\stable-2.3.x\src\github.com\docker\pinata\win\src\Docker.ApiServices\Mounting\FileSharing.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Docker.ApiServices.Mounting.FileSharing.d__4.MoveNext() in C:\workspaces\stable-2.3.x\src\github.com\docker\pinata\win\src\Docker.ApiServices\Mounting\FileSharing.cs:line 47\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Docker.HttpApi.Controllers.FilesharingController.d__2.MoveNext() in C:\workspaces\stable-2.3.x\src\github.com\docker\pinata\win\src\Docker.HttpApi\Controllers\FilesharingController.cs:line 21\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Threading.Tasks.TaskHelpersExtensions.d__1`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__15.MoveNext()"}

Typo in Chapter 2 Quiz

Chapter 2 Chapter Quiz

Title: Chapter Quiz

Description: Typo in question 2

solcing -> solving

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.