Skip to content

reload() doesnt work because of _should_rewrite() #3852

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

Closed
4 tasks done
fersarr opened this issue Aug 22, 2018 · 3 comments
Closed
4 tasks done

reload() doesnt work because of _should_rewrite() #3852

fersarr opened this issue Aug 22, 2018 · 3 comments

Comments

@fersarr
Copy link

fersarr commented Aug 22, 2018

  • Include a detailed description of the bug or suggestion

using reload(mymodule) or imp.reload(mymodule) inside a test is failing because _should_rewrite() gets called and it incorrectly thinks that mymodule is a conftest/test file when it is not and because of that it doesn't get reloaded.

The problem seems to be here:

if name == marked or name.startswith(marked + "."):

where name is

xxxx.name1.name2

and self._must_rewrite is

set(['pytest_server_fixtures', 'tests', 'common_setup', 'setup', 'xdist', 'xxxx', 'xxxx.testing.pytest.name3', 'pytest_shutil', 'conftest', 'pytest_svn', 'pytest_verbose_parametrize', 'pytest_qt_app',

*note: xxxx is our company's namespace

so,

when name is 'xxxx.name1.name2' and marked is xxxx, name.startswith(..) returns True

This seems to result from the fact that we have a testing module inside our company's namespace. It is called xxxx.testing.

This used to work on pytest 2.9.1

  • pip list of the virtual environment you are using
alembic (0.7.4)
click (6.2)
fixtures (3.0.0)
..
mock (1.0.1)
mockextras (1.0.2)
pytest (3.7.2)
pytest-cov (2.2.1)
pytest-fixture-config (1.0.1)
pytest-profiling (1.2.6)
pytest-qt-app (1.0.1)
pytest-shutil (1.2.8)
pytest-svn (1.2.2)
pytest-verbose-parametrize (1.3.0)
pytest-virtualenv (1.2.7)
pytest-xdist (1.14)
python-dateutil (2.4.2)
python-gnupg (0.3.3)
python-jenkins (0.2)
python-ldap (2.3.12)
python-mimeparse (1.5.2)
python-snappy (0.5)
python-subunit (1.2.0)
...

  • pytest and operating system versions

Python 2.7.11
64 bit Linux RHEL7
pytest 3.7.2 (also tried on 3.0.6 and 3.1.0 and 2.9.1) - only 2.9.1 worked

  • Minimal example if possible

have a namespace yyy with a namespace package yyy.testing that includes testing utilities. Then write tests for another package yyy.mymodule and use reload() inside the tests to re-initialize things inside mymodule

@RonnyPfannschmidt
Copy link
Member

i believe we should document that reload is only supported with plain assertion or with disabled assertion rewriting

reload in general is considered a bad practice in python

@fersarr
Copy link
Author

fersarr commented Aug 22, 2018

I agree, it's a code smell, didn't like it when i saw it... but it used to work so I'm just reporting it.

@Zac-HD
Copy link
Member

Zac-HD commented Oct 20, 2018

Duplicate of #743 and #3539, fixed by #4022.

@Zac-HD Zac-HD closed this as completed Oct 20, 2018
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

3 participants