python


I want to make my pytest unittests run with the “python setup.py test” command


In the default behaviour giving the command python setup.py test will execute the unit tests associated with a module. This default behaviour can be made to work simply by providing a list of test-suite modules.
The alternative (but now obsolete) Nose test runner has a comparable feature - you can just provide the string nose.collector which gives the test command the ability to auto-discover the tests associated with the project.
But what if I'm using pytest? There doesn't seem to be a documented pattern to run tests from the setup.py file. Is this a behaviour supported by the pytest library?
I personally have not done this. But I'd recommend checking out some legit python projects on github to see how they have done this.
E.g. requests:
#!/usr/bin/env python
import sys
from setuptools import setup
from setuptools.command.test import test as TestCommand
class PyTest(TestCommand):
user_options = [('pytest-args=', 'a', "Arguments to pass into py.test")]
def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = []
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
import pytest
errno = pytest.main(self.pytest_args)
sys.exit(errno)
setup(
# pass all the required/desired args
cmdclass={'test': PyTest}
)
You can even pass args to pytest runner python setup.py test --pytest-args='-vvv'

Related Links

Can't export Cassandra table using Python
matplotlib animation blit=True causes KeyError
python traceback - performance problems
Superimposition of histogram and density in Pandas/Matplotlib in Python
python share thread-objects in manager.dict() between 2 processes
How to get tcp raw data in pox
aiohttp and client-side SSL certificates
Django admin page 404
# -*- coding: utf-8 -*- in __init__.py [duplicate]
Python - Download Images from a list of urls in a csv and rename images from custom list
Matplotlib customize pie chart labels and dropshadow
Seaborn - Why import as sns?
Renaming the Columns in Self-Join of data frame in Spark
How to upload image using ckeditor in django?
Implementing Django style API, chaining dots, inheritance
Python ~ Getting first few numbers from left to right

Categories

HOME
converter
cakephp-3.x
ibm-watson-cognitive
tinyos
wmic
nuxeo
backup
computer-vision
docker-swarm
h2
browserify
codeblocks
internet-explorer-11
slim-3
android-viewpager
uiactivityviewcontroller
criteria
pjsip
outlook-web-addins
cakephp-2.9
gatsby
abcpdf
propel2
pycrypto
aws-cognito
shippo
statusbar
os161
dspic
rworldmap
qsub
samsung-mobile
bus-error
interrupt-handling
fileinfo
dd-wrt
superscript
hawtio
nsurlconnection
transient
concrete5-5.7
s3cmd
socketscan
bayesian-networks
amd
z3py
context-free-language
data-integration
defold
volume
pagefile
ingres
laravel-query-builder
rsqlite
pspice
build-process
pdflib
cfeclipse
c#-interactive
update-site
pydio
try-finally
shipitjs
fps
concur
qt-linguist
asp.net-mvc-2
brackets-shell
asymptote
self-hosting
oai
js-cookie
sevenzipsharp
pyopengl
sparse-file
moai
livechat
snmp4j
libssh2
proxies
valence
funkload
broadcasting
resource-files
ksoap2
svcutil.exe
db4o
bigint
trimming
installshield-2009
ruboto
dropdownlistfor
moq-3
javascriptserializer
feof
deploying
xmlslurper
coff
windows-live-id
ets
recordset
communicationexception
graniteds
winsnmp
odbc-sql-server-driver
data-execution-prevention

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App