Title: Section 2.1: Note on `python3 -m pytest` is incorrect · Issue #18 · bham-carpentries/python-intermediate-development · GitHub
Open Graph Title: Section 2.1: Note on `python3 -m pytest` is incorrect · Issue #18 · bham-carpentries/python-intermediate-development
X Title: Section 2.1: Note on `python3 -m pytest` is incorrect · Issue #18 · bham-carpentries/python-intermediate-development
Description: The note: ## Why Run Pytest Using `python3 -m pytest` and Not `pytest`? `pytest` is another Python module that can be run via its own command but this is a good example why invoking Python modules via `python3 -m` may be better (recall t...
Open Graph Description: The note: ## Why Run Pytest Using `python3 -m pytest` and Not `pytest`? `pytest` is another Python module that can be run via its own command but this is a good example why invoking Python modules ...
X Description: The note: ## Why Run Pytest Using `python3 -m pytest` and Not `pytest`? `pytest` is another Python module that can be run via its own command but this is a good example why invoking Python modules ...
Opengraph URL: https://github.com/bham-carpentries/python-intermediate-development/issues/18
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Section 2.1: Note on `python3 -m pytest` is incorrect","articleBody":"The note:\n\n```markdown\n## Why Run Pytest Using `python3 -m pytest` and Not `pytest`?\n\n`pytest` is another Python module that can be run via its own command but this is a good example\nwhy invoking Python modules via `python3 -m` may be better (recall the [explanation of Python interpreter's `-m` flag](12-virtual-environments.md)).\nHad we used `pytest tests/test_models.py` command directly,\nthis would have led to a \"ModuleNotFoundError: No module named 'inflammation'\" error. This is\nbecause `pytest` command (unlike `python3 -m pytest`) does not add the current directory to its list of\ndirectories to search for modules, hence the `inflammation` subdirectory's contents are not being\n'seen' by `pytest` causing the `ModuleNotFoundError`. There are ways to work around this problem\nbut `python3 -m pytest` ensures it does not happen in the first place.\n```\n\nThis is wrong. Counter example:\n\n```bash\npytest tests/test_models.py\n```\n\noutputs:\n\n```console\n=================================================== test session starts ====================================================\nplatform darwin -- Python 3.12.9, pytest-8.3.5, pluggy-1.5.0\nrootdir: /Users/***/Repos/github.com/***/python-intermediate-inflammation\nconfigfile: pyproject.toml\ncollected 2 items \n\ntests/test_models.py .. [100%]\n\n==================================================== 2 passed in 0.06s =====================================================\n```\n\n### Environment\n\n- OS: macOS 15.3.2\n- See pytest output above\n","author":{"url":"https://github.com/alexlyttle","@type":"Person","name":"alexlyttle"},"datePublished":"2025-04-01T14:08:40.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/18/python-intermediate-development/issues/18"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8fbb01c9-dbc7-51ed-5684-685de4434ddd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D306:205C7C:1CF33EF:29C5DAA:6A4BD266 |
| html-safe-nonce | 277aed886a07a32a1d12fb2cd6c8ba548f298233bbb61237f7c82c4af56cc31a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzA2OjIwNUM3QzoxQ0YzM0VGOjI5QzVEQUE6NkE0QkQyNjYiLCJ2aXNpdG9yX2lkIjoiNTkzMzg0MzMwNjU5Mjg1MDUzNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 394908a17fdbacb0e943fbc881f23c5c5533e73cca5f0cc80f0336c6af894eaa |
| hovercard-subject-tag | issue:2963581829 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/bham-carpentries/python-intermediate-development/18/issue_layout |
| twitter:image | https://opengraph.githubassets.com/048e41507d704dea893fea80003702cda92e281a37e14c3361b7523945697c2b/bham-carpentries/python-intermediate-development/issues/18 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/048e41507d704dea893fea80003702cda92e281a37e14c3361b7523945697c2b/bham-carpentries/python-intermediate-development/issues/18 |
| og:image:alt | The note: ## Why Run Pytest Using `python3 -m pytest` and Not `pytest`? `pytest` is another Python module that can be run via its own command but this is a good example why invoking Python modules ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | alexlyttle |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9df996be9551ac02247d09a2f7f64ece66c35ca28885d346e98fdfda9cdaa37b |
| turbo-cache-control | no-preview |
| go-import | github.com/bham-carpentries/python-intermediate-development git https://github.com/bham-carpentries/python-intermediate-development.git |
| octolytics-dimension-user_id | 41366779 |
| octolytics-dimension-user_login | bham-carpentries |
| octolytics-dimension-repository_id | 928344524 |
| octolytics-dimension-repository_nwo | bham-carpentries/python-intermediate-development |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | true |
| octolytics-dimension-repository_parent_id | 257930838 |
| octolytics-dimension-repository_parent_nwo | carpentries-incubator/python-intermediate-development |
| octolytics-dimension-repository_network_root_id | 257930838 |
| octolytics-dimension-repository_network_root_nwo | carpentries-incubator/python-intermediate-development |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b71208a1c9ec7ccf364087569d0551f665dda674 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width