jieter / django-tables2

django-tables2 - An app for creating HTML tables
https://django-tables2.readthedocs.io/en/latest/
Other
1.9k stars 429 forks source link

how to run tests and example project? #294

Closed timfeirg closed 8 years ago

timfeirg commented 8 years ago

I'm working on #288, stuck at adding tests, how to run tests?

running py.test at project root or tests folder will throw 13 errors like this one:

self = <LazySettings [Unevaluated]>, name = 'DEFAULT_INDEX_TABLESPACE'

    def _setup(self, name=None):
        """
            Load the settings module pointed to by the environment variable. This
            is used the first time we need any settings at all, if the user has not
            previously configured the settings manually.
            """
        settings_module = os.environ.get(ENVIRONMENT_VARIABLE)
        if not settings_module:
            desc = ("setting %s" % name) if name else "settings"
            raise ImproperlyConfigured(
                "Requested %s, but settings are not configured. "
                "You must either define the environment variable %s "
                "or call settings.configure() before accessing settings."
>               % (desc, ENVIRONMENT_VARIABLE))
E           ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

/usr/local/lib/python2.7/site-packages/django/conf/__init__.py:41: ImproperlyConfigured

So I added this to tests/__init__.py:

import django
from django.conf import settings

settings.configure()
django.setup()

and then py.test gives me 10 other error:

template_name = 'test_template_column.html', dirs = <object object at 0x1054f3900>, using = None

    def get_template(template_name, dirs=_dirs_undefined, using=None):
        """
        Loads and returns a template for the given name.

        Raises TemplateDoesNotExist if no such template exists.
        """
        chain = []
        engines = _engine_list(using)
        for engine in engines:
            try:
                # This is required for deprecating the dirs argument. Simply
                # return engine.get_template(template_name) in Django 1.10.
                if isinstance(engine, DjangoTemplates):
                    return engine.get_template(template_name, dirs)
                elif dirs is not _dirs_undefined:
                    warnings.warn(
                        "Skipping template backend %s because its get_template "
                        "method doesn't support the dirs argument." % engine.name,
                        stacklevel=2)
                else:
                    return engine.get_template(template_name)
            except TemplateDoesNotExist as e:
                chain.append(e)

>       raise TemplateDoesNotExist(template_name, chain=chain)
E       TemplateDoesNotExist: test_template_column.html

/usr/local/lib/python2.7/site-packages/django/template/loader.py:43: TemplateDoesNotExist

I think I must be running tests the wrong way, can someone tells me how to run tests with this django project properly configured?

jieter commented 8 years ago

Test: run tox for all the environments, or tox py27-1.9 for python 2.7 with django 1.9. (needs tox installed) I run py.test without tox like this: PYTHONPATH=/home/jieter/workspace/django-tables2 py.test (needs the requirements in requirements/common.pip installed, usually in a virtualenv)

jieter commented 8 years ago

The example project is a bit broken.

If you still don't manage to run the test, just open a pull request with your work in progress, and travis CI will run the tests for you

timfeirg commented 8 years ago

cool!

I forgot to mention the example project, I noticed the brokenness, I wanted to fix that and add some more docs and examples regarding pandas, are there any guidelines for writing examples?

also, can I drop support for django<=1.8 in the example project?

jieter commented 8 years ago

@timfeirg I'm actually fixing the example project in #293. I think we should not have a different set of versions supported for django-tables2 in general vs. the example project, so for now, we still need to support 1.7 and 1.8...

timfeirg commented 8 years ago

@jieter could you take a look at the travis build of my PR?

I'm trying to get the tests working so I can write my own tests, but I think there's still something wrong with my setup or something.

it's complaining 3 failure and 1 error, but I don't think my commit would have cause such failure, are they broken tests?

For example, in the current master, test_general.test_should_support_safe_verbose_name_via_model will throw an exception telling me to add the django_db mark, so I did what it told me to and this error will go away

sorry I've been asking a lot, total newbie here

jieter commented 8 years ago

Strange failures indeed. The latest master ran just fine. Are you sure you have the versions specified in the requirements file installed (what does pip freeze look like)? Do you use tox or py.test manually?

Can you try to run the tests on a clean clone of the repo on your machine?

jieter commented 8 years ago

Interesting. This is how a clean install looks on my machine: https://gist.github.com/jieter/e0c2f577fe3c685edd04

I'll have look at the errors.

timfeirg commented 8 years ago

yeah...weird, I have failures and no InvocationError, your gist has InvocationError but no failures, while travis has both

jieter commented 8 years ago

InvocationError is for flake8, not the units tests... If you use tox, you'll get that too.

jieter commented 8 years ago

Running PYTHONPATH=/home/jieter/tmp/django-tables2 py.test works just fine.

jieter commented 8 years ago

No clue what's wrong. Are you sure your working copy is clean?

timfeirg commented 8 years ago

Entirely my fault, nothing wrong with the code, I've pip install -e django-tables2-timfeirg-fork, so when I run PYTHONPATH=pwdpy.test. in the clean clone, I'm actually testing my own fork, which means my commit have caused all the failures.

Sorry for all the trouble.

jieter commented 8 years ago

Never mind.

Consider using throwaway virtualenvs for this kind of things. Make sure you have a clean environment all the time.