
GITHUB . COM {
}
Detected CMS Systems:
- Wordpress (2 occurrences)
Title:
AttributeError: Test modules cannot use parent module's attributes under `--import-mode=importlib` Β· Issue #10337 Β· pytest-dev/pytest
Description:
a detailed description of the bug or problem you are having output of pip list from the virtual environment you are using pytest and operating system versions minimal example if possible Description of the bug: Pytest when executed under...
Website Age:
17 years and 8 months (reg. 2007-10-09).
Matching Content Categories {π}
- Education
- Technology & Computing
- Family & Parenting
Content Management System {π}
What CMS is github.com built with?
Github.com uses WORDPRESS.
Traffic Estimate {π}
What is the average monthly size of github.com audience?
ππ Tremendous Traffic: 10M - 20M visitors per month
Based on our best estimate, this website will receive around 10,653,926 visitors per month in the current month.
check SE Ranking
check Ahrefs
check Similarweb
check Ubersuggest
check Semrush
How Does Github.com Make Money? {πΈ}
Subscription Packages {π³}
We've located a dedicated page on github.com that might include details about subscription plans or recurring payments. We identified it based on the word pricing in one of its internal links. Below, you'll find additional estimates for its monthly recurring revenues.How Much Does Github.com Make? {π°}
Subscription Packages {π³}
Prices on github.com are in US Dollars ($).
They range from $4.00/month to $21.00/month.
We estimate that the site has approximately 5,316,180 paying customers.
The estimated monthly recurring revenue (MRR) is $22,327,958.
The estimated annual recurring revenues (ARR) are $267,935,490.
Wordpress Themes and Plugins {π¨}
What WordPress theme does this site use?
It is strange but we were not able to detect any theme on the page.
What WordPress plugins does this website use?
It is strange but we were not able to detect any plugins on the page.
Keywords {π}
pytest, test, akhilramkee, module, modules, attributeerror, parent, issue, pytestimportlibissue, importlib, doctestmodules, added, nicoddemus, attribute, commented, jaraco, importmodeimportlib, child, def, assert, session, starts, platform, darwin, python, pluggy, rootdir, plugins, anyio, collected, fix, contributor, missing, draft, teststestsomethingpy, sign, attributes, bug, importmode, pytestimportlibissueteststesttemppy, passed, failed, mentioned, type, collection, authors, projects, description, problem, import,
Topics {βοΈ}
import-mode=importlib import-mode importlib respect import-mode doctest-modules /users/jaraco/draft plugins /private/tmp plugins test modules test suite failing [ 50%] pytest_importlib_issue/tests/test_temp importlib mode add child modules enabling doctest move tests/test_something py import pkg collection phase type activity akhilramkee mentioned personal information attributeerror test passes parent modules test_x - attributeerror [doctests] namespace packages fix duplicated imports test_mod - attributeerror comment metadata assignees test assigned labels topic added akhilesh ramakrishnan type projects module 'pytest_importlib_issue' required fix lined projects milestone nicoddemus closed pip list py def importlib recent issue pytest pytest 7 pytest-7 collection related attribute similar namespace package attributeerror addressed type assert temp detailed description py βββ temp child module yeah module 'pkg'
Payment Methods {π}
- Braintree
Questions {β}
- Already have an account?
- Would you like to have your name added to AUTHORS as well @akhilramkee ?
- Any thoughts on this ?
Schema {πΊοΈ}
DiscussionForumPosting:
context:https://schema.org
headline:AttributeError: Test modules cannot use parent module's attributes under `--import-mode=importlib`
articleBody:<!--
Thanks for submitting an issue!
Quick check-list while reporting bugs:
-->
- [x] a detailed description of the bug or problem you are having
- [ ] output of `pip list` from the virtual environment you are using
- [x] pytest and operating system versions
- [x] minimal example if possible
**Description of the bug:**
Pytest when executed under `--import-mode=importlib` doesn't try to retain the child module as parent module's attribute if parent module is already in `sys.path`. This started happening in pytest 7.1.3 after enabling doctest to respect `import-mode` in https://github.com/pytest-dev/pytest/pull/10088.
**Minimal Example**
**File structure**
```
pytest_importlib_issue/
βββ __init__.py
βββ temp.py
βββ tests/
βββ test_temp.py
```
**temp.py**
```
def x():
"""
>>> assert 1==1
"""
return 2
```
**test_temp.py**
```
import pytest_importlib_issue
from pytest_importlib_issue import temp
def test_x():
assert temp.x() == 2
assert pytest_importlib_issue.temp.x() == 2
```
**Output** - MacOS 12.6
**pytest7.1.3 without importlib**
```
(pytest7.1.3) akhileshr@Akhileshs-MacBook-Air /tmp % pytest pytest_importlib_issue --doctest-modules
============================================================================================================ test session starts =============================================================================================================
platform darwin -- Python 3.9.10, pytest-7.1.3, pluggy-0.13.1
rootdir: /private/tmp
plugins: anyio-3.5.0, xdist-2.2.1, easyread-0.1.0, forked-1.3.0
collected 2 items
pytest_importlib_issue/temp.py . [ 50%]
pytest_importlib_issue/tests/test_temp.py . [100%]
============================================================================================================= 2 passed in 0.03s ==============================================================================================================
```
**pytest-7.1.3 with importlib**
```
(pytest7.1.3) akhileshr@Akhileshs-MacBook-Air /tmp % pytest pytest_importlib_issue --import-mode=importlib --doctest-modules
============================================================================================================ test session starts =============================================================================================================
platform darwin -- Python 3.9.10, pytest-7.1.3, pluggy-0.13.1
rootdir: /private/tmp
plugins: anyio-3.5.0, xdist-2.2.1, easyread-0.1.0, forked-1.3.0
collected 2 items
pytest_importlib_issue/temp.py . [ 50%]
pytest_importlib_issue/tests/test_temp.py F [100%]
================================================================================================================== FAILURES ==================================================================================================================
___________________________________________________________________________________________________________________ test_x ___________________________________________________________________________________________________________________
def test_x():
assert temp.x() == 2
> assert pytest_importlib_issue.temp.x() == 2
E AttributeError: module 'pytest_importlib_issue' has no attribute 'temp'
pytest_importlib_issue/tests/test_temp.py:6: AttributeError
========================================================================================================== short test summary info ===========================================================================================================
FAILED pytest_importlib_issue/tests/test_temp.py::test_x - AttributeError: module 'pytest_importlib_issue' has no attribute 'temp'
======================================================================================================== 1 failed, 1 passed in 0.08s =========================================================================================================
```
It could be seen that the failure happens when we try to access the child module through parent module.
**pytest-7.0.1 with importlib**
```
(pytest7.0.1) akhileshr@Akhileshs-MacBook-Air /tmp % pytest pytest_importlib_issue --import-mode=importlib --doctest-modules
============================================================================================================ test session starts =============================================================================================================
platform darwin -- Python 3.9.10, pytest-7.0.1, pluggy-0.13.1
rootdir: /private/tmp
plugins: anyio-3.5.0, xdist-2.2.1, easyread-0.1.0, forked-1.3.0
collected 2 items
pytest_importlib_issue/temp.py . [ 50%]
pytest_importlib_issue/tests/test_temp.py . [100%]
============================================================================================================= 2 passed in 0.03s ==============================================================================================================
```
This passes, because doctest-modules were using `prepend` instead of `importlib` before the PR. ( added this to state this is a recent issue ).
**Fix**: Child module has to be persisted in Parent module as an attribute similar to how `importlib.import_module` does.
author:
url:https://github.com/akhilramkee
type:Person
name:akhilramkee
datePublished:2022-10-04T17:19:25.000Z
interactionStatistic:
type:InteractionCounter
interactionType:https://schema.org/CommentAction
userInteractionCount:6
url:https://github.com/10337/pytest/issues/10337
context:https://schema.org
headline:AttributeError: Test modules cannot use parent module's attributes under `--import-mode=importlib`
articleBody:<!--
Thanks for submitting an issue!
Quick check-list while reporting bugs:
-->
- [x] a detailed description of the bug or problem you are having
- [ ] output of `pip list` from the virtual environment you are using
- [x] pytest and operating system versions
- [x] minimal example if possible
**Description of the bug:**
Pytest when executed under `--import-mode=importlib` doesn't try to retain the child module as parent module's attribute if parent module is already in `sys.path`. This started happening in pytest 7.1.3 after enabling doctest to respect `import-mode` in https://github.com/pytest-dev/pytest/pull/10088.
**Minimal Example**
**File structure**
```
pytest_importlib_issue/
βββ __init__.py
βββ temp.py
βββ tests/
βββ test_temp.py
```
**temp.py**
```
def x():
"""
>>> assert 1==1
"""
return 2
```
**test_temp.py**
```
import pytest_importlib_issue
from pytest_importlib_issue import temp
def test_x():
assert temp.x() == 2
assert pytest_importlib_issue.temp.x() == 2
```
**Output** - MacOS 12.6
**pytest7.1.3 without importlib**
```
(pytest7.1.3) akhileshr@Akhileshs-MacBook-Air /tmp % pytest pytest_importlib_issue --doctest-modules
============================================================================================================ test session starts =============================================================================================================
platform darwin -- Python 3.9.10, pytest-7.1.3, pluggy-0.13.1
rootdir: /private/tmp
plugins: anyio-3.5.0, xdist-2.2.1, easyread-0.1.0, forked-1.3.0
collected 2 items
pytest_importlib_issue/temp.py . [ 50%]
pytest_importlib_issue/tests/test_temp.py . [100%]
============================================================================================================= 2 passed in 0.03s ==============================================================================================================
```
**pytest-7.1.3 with importlib**
```
(pytest7.1.3) akhileshr@Akhileshs-MacBook-Air /tmp % pytest pytest_importlib_issue --import-mode=importlib --doctest-modules
============================================================================================================ test session starts =============================================================================================================
platform darwin -- Python 3.9.10, pytest-7.1.3, pluggy-0.13.1
rootdir: /private/tmp
plugins: anyio-3.5.0, xdist-2.2.1, easyread-0.1.0, forked-1.3.0
collected 2 items
pytest_importlib_issue/temp.py . [ 50%]
pytest_importlib_issue/tests/test_temp.py F [100%]
================================================================================================================== FAILURES ==================================================================================================================
___________________________________________________________________________________________________________________ test_x ___________________________________________________________________________________________________________________
def test_x():
assert temp.x() == 2
> assert pytest_importlib_issue.temp.x() == 2
E AttributeError: module 'pytest_importlib_issue' has no attribute 'temp'
pytest_importlib_issue/tests/test_temp.py:6: AttributeError
========================================================================================================== short test summary info ===========================================================================================================
FAILED pytest_importlib_issue/tests/test_temp.py::test_x - AttributeError: module 'pytest_importlib_issue' has no attribute 'temp'
======================================================================================================== 1 failed, 1 passed in 0.08s =========================================================================================================
```
It could be seen that the failure happens when we try to access the child module through parent module.
**pytest-7.0.1 with importlib**
```
(pytest7.0.1) akhileshr@Akhileshs-MacBook-Air /tmp % pytest pytest_importlib_issue --import-mode=importlib --doctest-modules
============================================================================================================ test session starts =============================================================================================================
platform darwin -- Python 3.9.10, pytest-7.0.1, pluggy-0.13.1
rootdir: /private/tmp
plugins: anyio-3.5.0, xdist-2.2.1, easyread-0.1.0, forked-1.3.0
collected 2 items
pytest_importlib_issue/temp.py . [ 50%]
pytest_importlib_issue/tests/test_temp.py . [100%]
============================================================================================================= 2 passed in 0.03s ==============================================================================================================
```
This passes, because doctest-modules were using `prepend` instead of `importlib` before the PR. ( added this to state this is a recent issue ).
**Fix**: Child module has to be persisted in Parent module as an attribute similar to how `importlib.import_module` does.
author:
url:https://github.com/akhilramkee
type:Person
name:akhilramkee
datePublished:2022-10-04T17:19:25.000Z
interactionStatistic:
type:InteractionCounter
interactionType:https://schema.org/CommentAction
userInteractionCount:6
url:https://github.com/10337/pytest/issues/10337
Person:
url:https://github.com/akhilramkee
name:akhilramkee
url:https://github.com/akhilramkee
name:akhilramkee
InteractionCounter:
interactionType:https://schema.org/CommentAction
userInteractionCount:6
interactionType:https://schema.org/CommentAction
userInteractionCount:6
External Links {π}(2)
Analytics and Tracking {π}
- Site Verification - Google
Libraries {π}
- Clipboard.js
- D3.js
- Lodash
Emails and Hosting {βοΈ}
Mail Servers:
- aspmx.l.google.com
- alt1.aspmx.l.google.com
- alt2.aspmx.l.google.com
- alt3.aspmx.l.google.com
- alt4.aspmx.l.google.com
Name Servers:
- dns1.p08.nsone.net
- dns2.p08.nsone.net
- dns3.p08.nsone.net
- dns4.p08.nsone.net
- ns-1283.awsdns-32.org
- ns-1707.awsdns-21.co.uk
- ns-421.awsdns-52.com
- ns-520.awsdns-01.net