I implemented a python web client that I would like to test.
The server is hosted in npm registry. The server gets ran locally with node before running my functional tests.
How can I install properly the npm module from my setup.py script?
Here is my current solution inspired from this post:
class CustomInstallCommand(install):
def run(self):
arguments = [
'npm',
'install',
'--prefix',
'test/functional',
'promisify'
]
subprocess.call(arguments, shell=True)
install.run(self)
setup(
cmdclass={'install': CustomInstallCommand},
npm allows installing packages globally or local to a project. In pip , all packages are installed globally. To separate the local dependencies from system-wide packages, a virtual environment is created which contains all the dependencies local to the project and even a local Python distribution.
Installing Python Packages with Setup.py To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.
from setuptools.command.build_py import build_py
class NPMInstall(build_py):
def run(self):
self.run_command('npm install --prefix test/functional promisify')
build_py.run(self)
OR
from distutils.command.build import build
class NPMInstall(build):
def run(self):
self.run_command("npm install --prefix test/functional promisify")
build.run(self)
finally:
setuptools.setup(
cmdclass={
'npm_install': NPMInstall
},
# Usual setup() args.
# ...
)
Also look here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With