import os

from invoke import run, task


@task
def test(speed='fast'):
    if speed == 'fast':
        os.environ['DATABASE_URL'] = "sqlite://"
    run("coverage run manage.py test")
    run("coverage html")

import os

from invoke import run, task


@task
def test(speed='fast'):
    if speed == 'fast':
        os.environ['DATABASE_URL'] = "sqlite://"
    run("py.test")

Use py.test for running tests in invoke tasks file