mercredi 5 juillet 2017

Python tox and py.test: how to run just a single test rather than the whole test suite

I'm new to Django and testing so please bear with me.

Trying to run on the terminal a new test for code I developed in a Django project, but unfortunatly I inherited several test failures (already confirmed that by analyzing commits prior to mine). I'm trying to run/fix just my test/code. Not fix all the failling tests (at least not right now). Today we run the tests by just running tox in the main project folder, and tox ends up calling py.test, with a different database (in development/production we use Postgresql, but for tests we use SQLite). Here is the tox.ini configuration

[tox]
envlist = unit
skipsdist = True

[testenv:unit]
deps = -rrequirements/test.txt
commands =
    bash -c 'TESTING_DB=db.sqlite3 python manage.py initdb --settings telessaude.settings.test'
    py.test -n 4

passenv = *
setenv =
    DJANGO_SETTINGS_MODULE=telessaude.settings.test
whitelist_externals =
    /bin/bash

[flake8]
max-line-length = 110 

[pytest]
setenv=
    DJANGO_SETTINGS_MODULE=telessaude.settings.test
python_files = **/tests.py **/tests/*.py **/tests.py
norecursedirs = requirements .tox media

And here is my test, located at ~/project_name/servicos/tests.py

# encoding: utf-8
from fluxos.tests import BaseFluxoTestCase
from core.tests import BaseTestCase
from servicos.models import Estomatologia


class EstomatologiaTestCase(BaseTestCase):

    def testa_formata_campos(self):
        estomato = Estomatologia()
        return_value = estomato.formata_campos()
        self.assertEquals(return_value['comorbidades_paciente'], '')

    ...

What should I do with either tox or py.test to run just this newly created test? Thanks!

Aucun commentaire:

Enregistrer un commentaire