I am writing afew test cases using pytest for my django project. I have created an .ini file in the root directory as follow:
python_files =
tests.py
test_*.py
*_tests.py
*_test.py
norecursedirs =
devops
docs
media
settings
common
templates
addopts =
--maxfail=9999
--showlocals
--color=yes
--runxfail
--strict-markers
--durations=30
-r a
; --reuse-db
--no-migrations
--pdbcls=IPython.terminal.debugger:TerminalPdb
and in the main directory created a folder /devops and inside a bash file called backend_tests.sh like:
#!/usr/bin/env bash
options =("--cov")
options =("--disable-warnings")
echo "launch pytest ${options[@]}"
poetry run pytest "${options[@]}"
if [[ $? == 1 ]]; then exit 1; fi
when I run devops/backend_tests.sh it shows, collected 0 items but when I move backend_tests.sh to main directory and run ./backend_tests.sh it shows collected 5 items (which means loading test cases.
CodePudding user response:
If no parameters are given to pytest, it discovers tests recursively from the current path. So if you want to use the same command, you could just change the path where it is executed:
pushd <test_path>
poetry run pytest
popd
You can also give the tests or test paths on the command line, so the shortest way would just be:
poetry run pytest <test_path>
(where <test_path> in your case could just be ..)
