AJMansfield
AJMansfield

Reputation: 4129

Where to put tests for subpackages in python?

When a python module has multiple subpackages, where should tests for features in those subpackages be placed?

I can see two ways it could be done:

However it's not clear which option should be preferred.

For a package foo arranged like this:

foo/
  __init__.py
  bar.py
  baz/
    __init__.py
    baz.py

Do I put the tests here?

foo/
  __init__.py
  bar.py
  baz/
    __init__.py
    baz.py
  test/
    __init__.py
    test_bar.py
    baz/
      __init__.py
      test_baz.py

Or here?

foo/
  __init__.py
  bar.py
  baz/
    __init__.py
    baz.py
    test/
      __init__.py
      test_baz.py
  test/
    __init__.py
    test_bar.py

Upvotes: 6

Views: 2049

Answers (1)

eagle33322
eagle33322

Reputation: 227

There is a similar answer here:

https://stackoverflow.com/a/24266885/6529424

But it really comes down to preference/style or it depends on whatever framework you use to test your code.

Upvotes: 1

Related Questions