0

I have the following directory structure, as recommended in the pytest docs :

setup.py src/ mypkg/ __init__.py app.py view.py tests/ __init__.py unit/ __init__.py app_test.py integration/ __init__.py app_test.py 

All init.py files are empty for now.

And setup.py contains:

from setuptools import setup, find_packages setup(name="mypkg", packages=find_packages()) 

I want to use pytest for testing.

The command i use to run tests is

 pytest ./tests/unit/app_test.py 

How do I import app.py into app_test.py and make sure my tests can run without issue.

Ideally, I want a pythonic/clean way to resolve this, not a hack.

I've stumbled upon many questions in regards to this, such as :
How do I run all Python unit tests in a directory?

Running unittest with typical test directory structure

But somehow I can't get it to work with my use case. Can anybody pinpoint in the right direction ?

1 Answer 1

0

Alright I got what i was looking for with :

setup.py src/ main.py __init__.py tests/ __init__.py unit/ __init__.py app_test.py integration/ __init__.py app_test.py 

In app_test.py simply,

 import src.main 

Running tests with :

pytest ./tests/unit/app_test.py 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.