Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception with os.system call #284

Open
ivannnnnnnnnn opened this issue Jul 1, 2022 · 4 comments
Open

Exception with os.system call #284

ivannnnnnnnnn opened this issue Jul 1, 2022 · 4 comments

Comments

@ivannnnnnnnnn
Copy link

Hello, I am using pytest in my django application. I am write a method with call os.system function and when I run tests I catch exception

    def _update_group_permissions(self, request):
        group = settings.CONSTANCE_GROUP_FOR_FTP_USERS
        folder = settings.CONSTANCE_USER_FOLDERS  # Expected .../folder_name/
        try:
            os.system(f"chgrp {group} {folder[-1]}")
            os.system(f"chgrp {group} {folder}*")
            os.system(f"chmod 070 {folder[-1]}")
            os.system(f"chmod 070 {folder}*")
            self.message_user(
                request,
                f"Add permissions for folder to `{group}` group",
                level=messages.SUCCESS,
            )
        except Exception as e:
            self.message_user(
                request,
                f"Failed to add permissions for group `{group}`. {str(e)}",
                level=messages.SUCCESS,
            )


FAILED apps/accounts/admin.py::BLACK
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/pytest/__main__.py", line 7, in <module>
    raise SystemExit(pytest.main())
  File "/usr/local/lib/python3.7/dist-packages/_pytest/config/__init__.py", line 125, in main
    config=config
  File "/usr/local/lib/python3.7/dist-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/usr/local/lib/python3.7/dist-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/local/lib/python3.7/dist-packages/pluggy/manager.py", line 87, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/usr/local/lib/python3.7/dist-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/usr/local/lib/python3.7/dist-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/local/lib/python3.7/dist-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.7/dist-packages/_pytest/main.py", line 240, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/usr/local/lib/python3.7/dist-packages/_pytest/main.py", line 229, in wrap_session
    session=session, exitstatus=session.exitstatus
  File "/usr/local/lib/python3.7/dist-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/usr/local/lib/python3.7/dist-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/local/lib/python3.7/dist-packages/pluggy/manager.py", line 87, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/usr/local/lib/python3.7/dist-packages/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "/usr/local/lib/python3.7/dist-packages/_pytest/terminal.py", line 731, in pytest_sessionfinish
    self.write_sep("!", session.shouldfail, red=True)
  File "/usr/local/lib/python3.7/dist-packages/_pytest/terminal.py", line 391, in write_sep
    self._tw.sep(sep, title, **markup)
  File "/usr/local/lib/python3.7/dist-packages/py/_io/terminalwriter.py", line 232, in sep
    N = max((fullwidth - len(title) - 2) // (2*len(sepchar)), 1)
TypeError: object of type 'bool' has no len()
make: *** [Makefile:15: test] Error 1

If I comment part with os.system all work correctly

Test requirements:

isort==4.3.21
ipython==5.8.0
black==19.3b0
coverage==5.2.1
pytest==5.4.3
pytest-black==0.3.10
pytest-django==3.9.0
pytest-isort==1.1.0
pytest-instafail==0.4.2
pytest-blockage==0.2.2
pytest-xdist==1.34.0
django-test-plus==1.4.0
fakeredis==1.4.5
bandit==1.7.0
pytest-bandit==0.5.2

Command for run tests:

pytest --black --ff --isort --blockage --instafail -n 0 --pdb -v
@RonnyPfannschmidt
Copy link
Member

At first glance i looks like something is setting a internal internal object to the wrong value, this is unrelated to os. System

Fyi, python has native apis for the stuff you shell out for, using those is probably a good idea anyway

@ivannnnnnnnnn
Copy link
Author

At first glance i looks like something is setting a internal internal object to the wrong value, this is unrelated to os. System

Fyi, python has native apis for the stuff you shell out for, using those is probably a good idea anyway

I catch same exception with any command in os.system. If I try call echo or ls I have same error

@RonnyPfannschmidt
Copy link
Member

Just realised that the pytest version is of the 5.x series, please update

@RonnyPfannschmidt
Copy link
Member

Also please excuse the delay, new baby in the family

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants