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

Apache not serving admin static files for django
Django dynamic object listing with foreign tables (many to many case)
aysncio cannot read stdin on Windows
Write multiple matches from regex to a file on a single line a certain way
one or more most frequent letter in string python
pandas - select/mask the first n elements by value
python filter files by modified time
Python, Multiprocessing: what to do if process.join() waits forever?
How to sum values in an iterator in a PySpark groupByKey()
Allauth will not save additional fields
Read Flask Session Cookie
How do I make my script take only numeric inputs without screwing it up
Incorrect output while reading text file in Python
PhantomJS - Permission Denied
Combining image RGB channels
Python input validation and edge case handling

Categories

HOME
paypal
mql4
answer-set-programming
signalr
websphere
rotation
vs-team-services
ubuntu-12.04
jscript
hyperledger-fabric
snap.svg
eval
onenote-api
facebook-javascript-sdk
jboss-eap-7
data-analysis
x-frame-options
sign
rebol2
cloudflare
phpbb
arm-template
off-canvas-menu
internet-explorer-8
ip-camera
jive
google-ima
myob
shopping-cart
visual-c++-2017
jenkins-job-dsl
continuous-deployment
web-frontend
edge-detection
data-conversion
reactiveui
referenceerror
rowcount
stocks
pdflatex
openpgp
geomesa
topic-modeling
s3cmd
android-preferences
wcf-security
web-development-server
distributed-transactions
sapui
spell-checking
decompress
slidesjs
modelattribute
paas
redux-router
spring-ioc
instruments
pagekit
jackson-databind
string-parsing
faraday
date-format
dac
brackets-shell
altbeacon
eyeql
wikitext
risk-analysis
castle-windsor-3
ffprobe
guzzle6
jcr-sql2
activity-streams
utf-32
candidate-key
surrogate-key
config-files
jstack
visualstatemanager
reserved-words
circos
baucis
document-database
nimrod
sql-server-2012-web
ruboto
qtgui
vertical-scrolling
objcmongodb
fieldset
abnf
tridion2009
cbcentralmanager
pitch
blockingqueue
rose-db-object
viewdidload
testunit
ihttphandler
external-assemblies
usability-testing
handheld
document-library

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