(Pytest-Xdist) ModuleNotFoundError: No module named 'execnet.rsync' - python

I have been trying to bundle my tests written on pytest as .exe file.
I have tried the code mentioned in the pytest documentation for including the third party plugins:
https://docs.pytest.org/en/latest/example/simple.html#freezing-pytest
My code is as follows:
import pytest
import xdist
import pytest_rerunfailures
if len(sys.argv) > 1 and sys.argv[1] == "--pytest":
sys.exit(pytest.main(sys.argv[2:], plugins=[xdist, pytest_rerunfailures]))
Interestingly, the code works for pytest_rerunfailures but when I run the .exe using -n 2, it shows the following error:
ERROR: usage: mainfile [options] [file_or_dir] [file_or_dir] [...]
mainfile: error: unrecognized arguments: -n
inifile: None
rootdir: A:\New folder (2)\Scripted\dist
Here mainfile is the name of the exe file.
Also, it would be worth mentioning that xdist command-line options work when the tests are run normally but when bundled as exe, the create this issue.
ModuleNotFoundError: No module named 'execnet.rsync'
Could someone help me out here?

Related

Crypto Module not Found for pyinstaller

I want to turn my Python script into a single executable with all the dependencies in place. For this purpose I am using pyinstaller. I have installed it globally on my machine and set up a virtualenv for my project. While the virtualenv is active I am executing the following command:
pyinstaller --onefile --paths /path/to/venv/lib/python3.9/site-packages script.py
This creates an executable but when I try to run it it gives me:
ModuleNotFoundError: No module named 'Crypto.Util.Padding'
In the warning file it gives me the following line:
missing module named 'Crypto.Util.Padding' - imported by sp_api.base.helpers (top-level)
And during executable generation the output includes:
6427 INFO: Loading module hook 'hook-Crypto.py' from '/home/user/.local/lib/python3.9/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
Traceback (most recent call last):
File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'Crypto.Math'
When executing the command
pyinstaller --onefile myscript.py
under windows, it works perfectly fine even without specifying the venv path. When performing the same step in linux, the executable fails with the first non-standard import (flask in this case).
After also adding the path for lib64 from the corresponding venv the Crypto library is found.
pyinstaller --onefile --paths /path/to/venv/lib/python3.9/site-packages \
--paths /path/to/venv/lib64/python3.9/site-packagesscript.py

How to solve the ERROR: usage: _jb_pytest_runner.py error running the SHAP test-cases with PyCharm?

I cannot get around this error while trying to run the shap test-cases with PyCharm:
/home/user/shap/venv/bin/python /home/user/Desktop/pycharm-community-2021.1.2/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py --path /home/user/shap/tests
Testing started at 10:51 a.m. ...
Launching pytest with arguments /home/user/shap/tests in /home/user/shap/tests
ERROR: usage: _jb_pytest_runner.py [options] [file_or_dir] [file_or_dir] [...]
_jb_pytest_runner.py: error: unrecognized arguments: --mpl --cov=shap --cov-report=term-missing
inifile: /home/user/shap/pytest.ini
rootdir: /home/user/shap
Process finished with exit code 4
Empty suite
I have tried different installations (pytest, pip and conda). I have also tried different Python versions as well as shap versions. Nothing worked.
Any help would be appreciated
Remove/Comment from pytest.ini the line of code how contains --mpl --cov=shap --cov-report=term-missing
Run again and now work (i hope)
The answer is simple.
Install everything using the PyCharm (Settings->Project->Project Interpreter, and press +) and not the pip (or other) from the command line.

Name 'pytest' is not defined. how to run testpy?

I have installed python with conda.
pytest --version
This is pytest version 3.0.5, imported from /home/fabiano/anaconda3/lib/python3.6/site-packages/pytest.py
My test script
def tc1():
given="49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d"
expected=b"SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t"
assert base64.b64encode(bytes.fromhex(given)) == expected
I have imported pytest
import pytest
I am trying some stuff with pytest.But when I try from Python shell,I have problems like this
testset.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'testset' is not defined
In my shell
pytest
<module 'pytest' from '/home/fabiano/anaconda3/lib/python3.6/site-packages/pytest.py'>
Where should I save testset.py file?
pytest does test discovery. The basic steps are well listed in their documentation
Name the file containing the test test_*.py or *_test.py.
Name the test functions in those files def test_*
For you test, place the following code in the file test_set.py:
import base64
def test_tc1():
given="49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d"
expected=b"SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t"
assert base64.b64encode(bytes.fromhex(given)) == expected
Navigate to the directory containing the file test_set.py and execute the pytest command:
pytest
Expected output:
user#pc:/tmp/test_dir $ pytest .
============================= test session starts ==============================
platform linux -- Python 3.5.2+, pytest-3.0.3, py-1.4.31, pluggy-0.4.0
rootdir: /tmp/test_dir , inifile: collected 1 items
test_set.py .
=========================== 1 passed in 0.01 seconds ===========================

ImportError: No module named Binary with pytest

I'm working through http://blog.thedigitalcatonline.com/blog/2015/05/13/python-oop-tdd-example-part1/#.Vw0NojFJJ9n .
When I try:
$ py.test
============================= test session starts =============================
platform win32 -- Python 3.2.5, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: C:\envs\r3\binary, inifile:
plugins: capturelog-0.7
collected 0 items / 1 errors
=================================== ERRORS ====================================
____________________ ERROR collecting tests/test_binary.py ____________________
tests\test_binary.py:3: in <module>
import Binary
E ImportError: No module named Binary
================= 1 pytest-warnings, 1 error in 0.20 seconds ==================
What am I doing wrong?
Add current directory to PYTHONPATH environmental variable.
As you are on Windows:
$ set PYTHONPATH="."
This shall help py.test to find and import the module.
Checking the py.test tutorial I see, that at "Writing the class" section they use exactly the same trick.
In practice, you do not have to do this, as you usually test against installed Python module (typically with setup.py in project root directory and using develop mode), and it is accessible for import easily without playing with PYTHONPATH.

Buildout + Nose failing with passed options options

After running a buildout operation on my project, I can run nose with the following command:
# ./bin/nosetests
----------------------------------------------------------------------
Ran 0 tests in 0.310s
However, when I try to pass options (such as -w for the base directory, I get the following:
# ./bin/nosetests -vv --detailed-errors --exe
Usage: nosetests [options]
nosetests: error: no such option: -v
I've checked the test files which are being ran, and removed all lines importing either getopt or OptionParser to ensure they're not getting in the way, but I'm still getting the same error regardless.
I believe one of the files we're testing requires getopt to function... is there any way I can get nosetests to work with buildout without these errors?
You can use noserunner buildout recipe
Here is example buildout.cfg:
[buildout]
parts = test
index = http://download.zope.org/simple
[test]
recipe = pbp.recipe.noserunner
eggs = pbp.recipe.noserunner
working-directory = ${buildout:directory}
This will create script test in bin directory. Runner will run all tests found in path set in working-directory

Categories

Resources