How do I just run the tests without executing the parent script in py.test? Currently I run command pytest -v
from directory Project_dir, and this runs script.py and tests finally in the end. Ideally only tests need to be run. Here is my current directory setup:
Project_dir
script.py
test
test_script.py
script.py
def add(a,b):
added = a + b
return added
x = add(1,3)
print x, 'yup'
test_script.py
import script
def test_add():
assert script.add(3,4) == 7
Working directory: Project_dir
Command: pytest -vs
========================================== test session starts ==========================================
platform darwin -- Python 2.7.10, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /usr/bin/python
cachedir: .cache
rootdir: **, inifile:
plugins: cov-2.4.0
collecting 0 items
Sum is 4
collected 1 items
test/test_script.py::test_add PASSED
======================================= 1 passed in 0.00 seconds ========================================
Sum is 4
shows the script.py executed fully instead of just the tests. It happens as the script.py is imported as module. But I keep thinking there must be a way to avoid this and just execute the tests directly.