Skip to content

Instantly share code, notes, and snippets.

@nicoddemus
Last active April 15, 2022 19:23
Show Gist options
  • Save nicoddemus/6abbc43236dd042fd053 to your computer and use it in GitHub Desktop.
Save nicoddemus/6abbc43236dd042fd053 to your computer and use it in GitHub Desktop.
Example on how to structure a package and testing modules

Arrange files like this:

apple/
  __init__.py
  apple.py
tests/
  test_everything.py

And execute with:

export PYTHONPATH=.
py.test

(This Gist was used to answer a question at stackoverflow)

def eat():
return 'eaten'
from apple import apple
def test_apple():
assert apple.eat() == 'eaten'
@valeriikundas
Copy link

@chrisamow I know, it's been a long long time. But did you solve that problem?

@xealits
Copy link

xealits commented Dec 25, 2019

Wanted to notice that you can run set an environment variable just for one command:

PYTHONPATH=. pytest

# or in fish shell
env PYTHONPATH=. pytest

It worked for me. Thanks for your example on SO!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment