Skip to content

Commit

Permalink
python.pkgs.pytest: setupHook to prevent creation of .pytest-cache fo…
Browse files Browse the repository at this point in the history
…lder, fixes #40273

When `py.test` was run with a folder as argument, it would not only
search for tests in that folder, but also create a .pytest-cache folder.
Not only is this state we don't want, but it was also causing
collisions.
  • Loading branch information
FRidh committed Jul 22, 2018
1 parent d5bb888 commit 610485f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkgs/development/python-modules/pytest/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ stdenv, buildPythonPackage, fetchPypi, attrs, hypothesis, py
, setuptools_scm, setuptools, six, pluggy, funcsigs, isPy3k, more-itertools
, atomicwrites, mock
, atomicwrites, mock, writeText
}:
buildPythonPackage rec {
version = "3.6.2";
Expand All @@ -27,6 +27,11 @@ buildPythonPackage rec {
runHook postCheck
'';

# Don't create .pytest-cache when using py.test in a Nix build
setupHook = writeText "pytest-hook" ''
export PYTEST_ADDOPTS="-p no:cacheprovider"
'';

meta = with stdenv.lib; {
maintainers = with maintainers; [ domenkozar lovek323 madjar lsix ];
platforms = platforms.unix;
Expand Down

5 comments on commit 610485f

@dotlambda
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FRidh I think this causes python.pkgs.pytestflakes to fail to build (found out using git bisect):

running install tests
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/nix/store/jzkbnbhgp6h838rby58ahah9bnidbi47-python3.6-pytest-3.6.2/lib/python3.6/site-packages/_pytest/main.py", line 174, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "/nix/store/jzkbnbhgp6h838rby58ahah9bnidbi47-python3.6-pytest-3.6.2/lib/python3.6/site-packages/_pytest/config/__init__.py", line 583, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "/nix/store/5l06yba5vxl45m5mrv6pgxyg7v1vs79b-python3.6-pluggy-0.6.0/lib/python3.6/site-packages/pluggy/__init__.py", line 628, in call_historic
INTERNALERROR>     res = self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/nix/store/5l06yba5vxl45m5mrv6pgxyg7v1vs79b-python3.6-pluggy-0.6.0/lib/python3.6/site-packages/pluggy/__init__.py", line 222, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/nix/store/5l06yba5vxl45m5mrv6pgxyg7v1vs79b-python3.6-pluggy-0.6.0/lib/python3.6/site-packages/pluggy/__init__.py", line 216, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/nix/store/5l06yba5vxl45m5mrv6pgxyg7v1vs79b-python3.6-pluggy-0.6.0/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/nix/store/5l06yba5vxl45m5mrv6pgxyg7v1vs79b-python3.6-pluggy-0.6.0/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/nix/store/5l06yba5vxl45m5mrv6pgxyg7v1vs79b-python3.6-pluggy-0.6.0/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/nix/store/vm12cdmv9xgr97j4cp4h6r23xc222qpf-python3.6-pytest-flakes-3.0.2/lib/python3.6/site-packages/pytest_flakes.py", line 36, in pytest_configure
INTERNALERROR>     config._flakes = FlakesPlugin(config)
INTERNALERROR>   File "/nix/store/vm12cdmv9xgr97j4cp4h6r23xc222qpf-python3.6-pytest-flakes-3.0.2/lib/python3.6/site-packages/pytest_flakes.py", line 44, in __init__
INTERNALERROR>     self.mtimes = config.cache.get(HISTKEY, {})
INTERNALERROR> AttributeError: 'Config' object has no attribute 'cache'
builder for '/nix/store/5468r0xibpvx6qddmlbx3ks6pv57hwln-python3.6-pytest-flakes-3.0.2.drv' failed with exit code 3

@FRidh
Copy link
Member Author

@FRidh FRidh commented on 610485f Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a hunch it was caused by this. I want to keep the hook because it is important, but we should see if we can find a solution for this package. We can export PYTEST_ADDOPTS="" for this package. We just need to remove the .pytest-cache ourselves then.

@dotlambda
Copy link
Member

@dotlambda dotlambda commented on 610485f Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never heard of PYTEST_ADDOPTS. If you know how to fix this, please do so.
Btw, this also breaks pytest-flake8.

@dotlambda
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes for pydocstyle.

@FRidh
Copy link
Member Author

@FRidh FRidh commented on 610485f Jul 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works better
FRidh@4b14e27

Please sign in to comment.