سؤال

I'm new to python, so I think it's more of an understanding thing that I am missing for this to not work.

I've started by creating a a new Pyramid project, so that my directory structure looks like:

MyProject /
    - myproject /
        - static
        - templates
        - tests.py
        - views.py
    - development.ini
    - production.ini
    - setup.py
    - setup.cfg

How ever, I'm adding a lot of my business/service logic to a myprojectlib package under the root package directory, and also created a tests package, like so:

MyProject /
    - myproject /
        - tests.py
        - views.py
    - myprojectlib /
        - user_service.py
    - tests /
        - user_tests.py
    - setup.py

I've added the init.py files to the 'myprojectlib' and 'tests' folder to make them packages, but I can't seem to get the user_tests.py file (and subsequent test code) to be included in the python setup.py test command. Only the myproject/tests.py tests are included.

My user_tests.py file contains a single test so far:

import unittest

class UserTests(unittest.TestCase):

    def test_user_can_register(self):

        #code removed for example

How I tell python to look for tests in the /tests directory also?

I've had a look at this post, and it seems I am doing all that it suggests: Having tests in multiple files

Thanks in advance for any help :)

Cheers, Justin

هل كانت مفيدة؟

المحلول

In the setup call in setup.py, try adding this:

  test_suite="tests",

as that's the directory that contain your tests. I typically structure my newer style packages like so and use nose to test so I don't have that in my setup.py. Adding that declaration, tests are now executed when python setup.py test is called.

Source: https://pythonhosted.org/setuptools/setuptools.html#test-build-package-and-run-a-unittest-suite

Again, ensure you have a __init__.py in the tests directory, else the setuptools test runner will complain about missing tests module.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top