samedi 17 août 2019

Running a fake redis for a python functional test running in a subprocess

I am writing a functional test for a program that reads data from stdin and then pushes it onto a Redis Queue. I have unittests, but also want a functional test that tests the whole process.

Ideally I don't want to have to run a real Redis server for the tests since installing and starting Redis is platform dependent. So is there a way I can have a fake redis server somehow that I can use in my test to see if "myprogram" indeed pushed something onto the right Redis key?

This is what my functional test looks like:

from subprocess import Popen, PIPE


def test_stdin():
    """Test sending data to stdin of LoraProcessor."""
    with Popen(["python3", "myprogram/myprogram.py"],
               stdin=PIPE) as proc:
        proc.communicate("some stdinline")

Aucun commentaire:

Enregistrer un commentaire