All Commands to run Pytest
চমৎকার 👍
এখন আমি তোমাকে pytest run করার সব Professional Command এক জায়গায় দিচ্ছি —
এগুলো office / production / CI/CD এ real engineer রা ব্যবহার করে।
⚠️ এটা শুধু basic না — complete command reference।
🧪 Pytest Run Commands — Full Professional Guide
✅ 1. Basic Test Run
সব test run করা
pytest
👉 pytest automatically search করবে:
test_*.py
*_test.py
Example Folder
project/
│
├── app/
└── tests/
├── test_user.py
└── test_payment.py
Run:
pytest
✅ 2. Verbose Mode (Most Used)
pytest -v
Output:
test_user.py::test_login PASSED
test_payment.py::test_pay PASSED
🔥 Office এ প্রায় সবসময় -v ব্যবহার হয়।
✅ 3. Specific File Run
একটা specific test file:
pytest tests/test_user.py
✅ 4. Specific Folder Run
pytest tests/unit/
✅ 5. Specific Test Function Run
pytest tests/test_user.py::test_login
✅ 6. Specific Class Run
pytest tests/test_user.py::TestUser
✅ 7. Keyword Search Run (🔥 Very Powerful)
pytest -k login
Run করবে:
test_login
test_login_fail
test_login_invalid
Multiple keyword:
pytest -k "login or payment"
Exclude keyword:
pytest -k "not slow"
✅ 8. Stop After First Failure
pytest -x
🔥 CI pipeline এ common।
✅ 9. Show Print Output
Normally pytest print hide করে।
Show করতে:
pytest -s
Example:
print("hello")
✅ 10. Fail Summary Only
pytest -q
Quiet mode।
✅ 11. Show Detailed Failure Trace
pytest --tb=long
Options:
--tb=short
--tb=line
--tb=no
✅ 12. Run Last Failed Tests
🔥 Senior Engineer Favourite
pytest --lf
Only last failed tests run করবে।
✅ 13. Run Failed First
pytest --ff
✅ 14. Run Tests in Parallel (VERY IMPORTANT)
Install:
pip install pytest-xdist
Run:
pytest -n auto
🔥 Huge speed improvement.
✅ 15. Code Coverage Run (Office Mandatory)
Install:
pip install pytest-cov
Run:
pytest --cov=app
Coverage report:
pytest --cov=app --cov-report=term
HTML report:
pytest --cov=app --cov-report=html
Open:
htmlcov/index.html
🔥 Industry standard।
✅ 16. Run Only Marked Tests
Example:
import pytest
@pytest.mark.slow
def test_big_process():
pass
Run:
pytest -m slow
Skip slow tests:
pytest -m "not slow"
✅ 17. Show Test Duration (Performance Debug)
pytest --durations=10
Slowest 10 tests দেখাবে।
✅ 18. Collect Tests Without Running
pytest --collect-only
🔥 Debugging structure এর জন্য useful।
✅ 19. Run With Debug Mode
pytest --pdb
Fail হলে debugger open হবে।
✅ 20. Run With Python Breakpoint
pytest --trace
✅ 21. Disable Warning
pytest --disable-warnings
✅ 22. Run Specific Test Line
pytest tests/test_user.py::test_login:15
✅ 23. Re-run Failed Tests Automatically
Install:
pip install pytest-rerunfailures
Run:
pytest --reruns 3
✅ 24. Run Tests Random Order
Install:
pip install pytest-randomly
Run:
pytest
✅ 25. Run Using Config File (Professional Way)
Create:
pytest.ini
[pytest]
testpaths = tests
addopts = -v
Now run:
pytest
Automatically settings apply হবে।
✅ 26. Continuous Testing (Watch Mode)
Install:
pip install pytest-watch
Run:
ptw
Code change → auto test run 🔥
✅ 27. Run Inside Docker
docker exec -it container pytest
✅ 28. CI/CD Run Example
GitHub Actions:
pytest -v --cov
🧠 Senior Engineer Daily Commands (MOST REALISTIC)
Engineer usually use:
pytest -v
During debugging:
pytest -k login -v -s
Before push:
pytest --cov
CI pipeline:
pytest -v --cov --maxfail=1
⭐ Pro Tip (Office Reality)
90% engineer এই ৬টা command ব্যবহার করে:
pytest
pytest -v
pytest -k keyword
pytest -x
pytest --lf
pytest --cov
🔥 Next Level (তুমি এখন প্রস্তুত):
আমি next এ শেখাতে পারি —
👉 pytest execution internally কীভাবে কাজ করে (Senior level knowledge)
👉 Fixture Deep Dive (hidden power)
👉 Mock & Patch full documentation ⚡
👉 Real API Testing using pytest
তুমি বলো — আমরা next expert topic শুরু করি 🚀.