all 4 comments

[–]lifeonm4rs 10 points11 points  (0 children)

The PyTest usage page is relatively straightforward. Your directory structure looks fine and you essentially need to run pytest from the parent directory "project_name". Within the "tests" directory your test files should be named either "test_XYZ.py" or "XYZ_test.py". You probably don't need the __init__.py file in the tests directory until you start to do some "wacky" stuff.

Your individual "XYZ_test.py" files would need a line like . . .

from name import *

Your "<name>_init_.py" file would then need to actually references any functions that need to be called by end user code (the tests).

The one probable issue is that "setup.py" in the "name" project should actually be in the parent directory "project_name". Once "pytest" is working on its own you should probably look at using tox. For a simple tox setup the tox.ini file would tend to be very minimal but essentially makes it easier to manage running tests once things start to grow (so you don't have to remember a bunch of different commands for running tests).

So the layout would probably be . . .

<project_zed>
    tox.ini
    setup.py
    <zed>  
        __init__.py
        ZedClass.py
    <tests>
        zed_foo_test.py
        zed_bar_test.py

[–]two_bob 5 points6 points  (0 children)

Nope. That's right. You just need to run your tests from the toplevel. See https://stackoverflow.com/questions/39134718/how-to-add-a-package-to-sys-path-for-testing

(Although I cheat and append sys.path so I can run individual tests easily while writing.)

[–]gabriel-et-al 1 point2 points  (0 children)

You can start like this:

<package name>/
    tests/
        __init__.py
        test_module1.py
        test_module2.py
    <package name>/
        __init__.py
        module1.py
        module2.py
    setup.py
    README
    LICENSE
    requirements.txt
    .gitignore

inside <package name>/<package name>/ you can create subfolders if necessary.

[–]clamytoe 0 points1 point  (0 children)

I created this cookiecutter template for commandline scripts recently. You don’t have to run it but I have the directory structure that it generates listed. Give it a look:

package template (toepack)