purgeable / testing-mwe-pytest-in-package Goto Github PK
View Code? Open in Web Editor NEWTesting pytest behaviour (and failures) in different settings.
Testing pytest behaviour (and failures) in different settings.
Following Gabriele suggestions I made a structrue in setting_4 that has a package called pkg and test folder in it.
test\test_in_sister_fodler.py has:
from ..pkg import code3
def test_foo():
assert code3.foo() == 1
print ("Test OK.")
I'm in root of this repo and I run python -m setting_4.test.test_in_sister_folder
or https://github.com/epogrebnyak/mwe-pytest-in-package/blob/master/run_test_setting_4.bat on Windows and it works.
My problem is that now py.test started from this root folder (and also from elsewhere) fails with:
__________ ERROR collecting setting_4/test/test_in_sister_folder.py ___________
setting_4\test\test_in_sister_folder.py:1: in <module>
from ..pkg import code3
E ValueError: attempted relative import beyond top-level package
Isn't that sad? I need a solution where I can both run
I basically try to replicate a setting from https://pytest.org/latest/goodpractises.html#choosing-a-test-layout-import-rules where tests are stored in a child (setting 3) or sister (setting 4) fodler relative to the script.
I have not done pip install -e
or any other command to register the package, that can be the reason. I do not understand what happens then and want stay wasy from it, if I can.
My intended result is to store tests in child or sister forlder and to be able to import a function from code3.py module with least extra settings (package setup, pythonpath, etc).
Need some changes in these lines of code and or some other action:
Also may help adding init.py to test folder, even though this is not encouraged in https://pytest.org/latest/goodpractises.html#choosing-a-test-layout-import-rules
A follow-up when people arrannge code into package, how they work on running it in due course of programming? In an IDE like Spyder (Anaconda native IDE) seems ther is now way to run a module inside a package. To people keep running python -m setting_4.test.test_in_sister_folder
or other python -m from cli? Or write code not a package first and do not modify it once it becomes a pakage? What is you typical procedure?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.