विभिन्न एनवायरनमेंट्स में अपना पैकेज टेस्ट करना

Python पैकेज विकसित करना

James Fulton

Climate informatics researcher

Python के कई वर्ज़न टेस्ट करना

यह setup.py Python 2.7 से आगे के किसी भी वर्ज़न की अनुमति देता है.

from setuptools import setup, find_packages

setup(
    ...
    python_requires='>=2.7',
)

इन Python वर्ज़न को टेस्ट करने के लिए आपको:

  • ये सभी Python वर्ज़न इंस्टॉल करने होंगे
  • हर Python में अपना पैकेज और सभी डिपेंडेंसीज़ इंस्टॉल करनी होंगी
  • pytest चलाना होगा
Python पैकेज विकसित करना

Python के कई वर्ज़न टेस्ट करना

यह setup.py Python 2.7 से आगे के किसी भी वर्ज़न की अनुमति देता है.

from setuptools import setup, find_packages

setup(
    ...
    python_requires='>=2.7',
)

इन Python वर्ज़न को टेस्ट करने के लिए आपको:

  • ये सभी Python वर्ज़न इंस्टॉल करने होंगे
  • tox चलाएँ
Python पैकेज विकसित करना

tox क्या है?

  • कई Python वर्ज़न पर टेस्ट चलाने के लिए डिज़ाइन किया गया
Python पैकेज विकसित करना

tox कॉनफ़िगर करें

कॉनफ़िगरेशन फ़ाइल - tox.ini

mysklearn/
|-- mysklearn
|   |-- ...
|-- tests
|   |-- ...
|-- setup.py
|-- LICENSE
|-- MANIFEST.in
|-- tox.ini   <--- configuration file
Python पैकेज विकसित करना

tox कॉनफ़िगर करें

कॉनफ़िगरेशन फ़ाइल - tox.ini

[tox]

envlist = py27, py35, py36, py37
[testenv]
deps = pytest
commands = pytest
echo "run more commands" ...
  • हेडिंग्स स्क्वेयर ब्रैकेट [...] में होती हैं.
  • Python वर्ज़न X.Y टेस्ट करने के लिए envlist में pyXY जोड़ें.
  • जिन Python वर्ज़न को आप टेस्ट करेंगे वे पहले से इंस्टॉल होने चाहिए.
  • commands पैरामीटर वे टर्मिनल कमांड्स सूचीबद्ध करता है जिन्हें tox चलाएगा.
  • commands सूची में कोई भी टर्मिनल कमांड हो सकते हैं, जैसे ls, cd, echo आदि.
Python पैकेज विकसित करना

tox चलाना

tox
mysklearn/    <-- यहाँ नेविगेट करें
|-- mysklearn
|   |-- ...
|-- tests
|   |-- ...
|-- setup.py
|-- LICENSE
|-- MANIFEST.in
|-- tox.ini
Python पैकेज विकसित करना

tox आउटपुट

py27 create: /mypackages/mysklearn/.tox/py27
py27 installdeps: pytest
py27 inst: /mypackages/mysklearn/.tox/.tmp/package/1/mysklearn-0.1.0.zip
py27 installed: mysklearn==0.1.0,numpy==1.16.6,pandas==0.24.2,pytest==4.6.11,...
py27 run-test-pre: PYTHONHASHSEED='2837498672'
...
Python पैकेज विकसित करना

tox आउटपुट

py27 run-test: commands[0] | pytest
======================== test session starts ========================
platform linux2 -- Python 2.7.17, ...
rootdir: /home/workspace/mypackages/mysklearn
collected 6 items                         

tests/preprocessing/test_normalize.py ...                     [ 50%]
tests/preprocessing/test_standardize.py ...                   [100%]

========================= 6 passed in 0.23s =========================
Python पैकेज विकसित करना

tox आउटपुट

...
__________________________ summary __________________________
  py27: commands succeeded
  py35: commands succeeded
  py36: commands succeeded
  py37: commands succeeded
Python पैकेज विकसित करना

tox आउटपुट

...
__________________________ summary __________________________
  py27: commands succeeded
  py35: commands succeeded
  py36: commands succeeded
ERROR:   py37: commands failed
Python पैकेज विकसित करना

अभ्यास करते हैं!

Python पैकेज विकसित करना

Preparing Video For Download...